Reputation: 1490
#include<stdio.h>
int main()
{
int i, j;
for(scanf("%d ",&i); i<=10; i++)
printf("%d ",i);
return 0;
}
I am a beginner in the programming world so please help me understand why on compiling the above C code it asks inputs twice.Maybe there's some logic to loop here I might be missing. Please help me understand.Thanks in advance.:)
Upvotes: 0
Views: 1672
Reputation: 1
I was facing the same problem and the only change I did was to change "%d " to "%d". This solves the problem.
Upvotes: 0
Reputation: 3
Currencly, you placed scanf() in a for loop, which it asks for input for a 10 times.This will not happen when you remove scanf() from for loop.
Upvotes: 0
Reputation: 73366
Change this:
scanf("%d ",&i);
to this:
scanf("%d",&i);
Read more in What does space in scanf mean?
Upvotes: 4