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; }

18th Jun 2022, 7:28 AM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
3 ответов
+ 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
18th Jun 2022, 9:40 AM
Chris Coder
Chris Coder - avatar
+ 1
Chris Coder thank you very much sir❤️
18th Jun 2022, 1:42 PM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
0
Jay Matthews when Enter any number =5 Natural number from 1 to 5 1 2 3 4 5
18th Jun 2022, 8:01 AM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar