0
Anyone explanation this for loop me.👉for(i=1; i<=n; i++). I'm bigger to the C language. All time i =1? Isn't then?
#include <stdio.h> int main() { int i, n; /* Input upper limit from user */ printf("Enter any number: "); scanf("%d", &n); printf("Natural numbers from 1 to %d : \n", n); /* * Start loop counter from 1 (i=1) and go till n (i<=n) * increment the loop count by 1 to get the next value. * For each repetition print the value of i. */ for(i=1; i<=n; i++) { printf("%d\n", i); } return 0; }
3 Antworten
+ 1
Your comment explains the for loop, and your code run shows what it does. Did you notice that i does not remain at 1?
In your case: i=1, since i is less than n , increment i ++ This (++) is the Increment operator - increases integer value by one.
loop repeats until i is equal to n
i = 1 + 1 = 2
i = 2 + 1 = 3
i = 3 + 1 = 4
...
when I = 5 stop
+ 1
Chris Coder thank you very much sir❤️
0
Jay Matthews when Enter any number =5
Natural number from 1 to 5
1
2
3
4
5