do{
scanf("%d %d", &n1, &n2);
sum = n1 + n2;
printf("%d\n", sum);
}while((scanf("%d %d", &n1, &n2) != '\n'));
Do you have a book about C? a manual?
Read something about scanf()
? You can try here in Microsoft Docs
It says
int scanf(
const char *format [,
argument]...
);
scanf()
returns a int
with the total read values, or EOF --- (-1) --- and you should use ALWAYS. Or better: should always use unless it is not important to know if you read something.
In your program used only once and in a strange way: you are trying to read two values:
scanf("%d %d", &n1, &n2)
then scanf()
will return what? -1 to EOF, zero, 1 or 2. And you will compare with what? '\n'
Which happens to be worth 10.
So it is not strange that your program stays in this loop for all eternity.
And why didn’t you test at first reading if you read two values? Do you think it will be all right if the guy type one? or none? Won’t go.
And noticed in the loop will never add up the even series?
Your program reads the first pair and sums up. There reads the second pair and the third before adding up. There goes the second. And there read the fourth and fifth before adding: there goes the fourth pair...
That’s if the guy actually types one pair at a time...
Tested it out?
You quoted that you got a "Time Limit Exceeded". Therefore, this code is an answer to a programming problem in the URI Online Judge/Hackerrank/etc style, correct?
– João Victor Sierra