For loop statement

For loop statement:

In for loop control statement, loop is executed until condition becomes false.

for new

Example 1

#include <stdio.h>

int main()

{

int j1;

for(j1=0;1j<10;j1++)

{

printf(“%d “,j1);

}

return 0; }

Output

0 1 2 3 4 5 6 7 8 9

 

Example 2

#include<stdio.h>

void main()

{

int num1, count1, sum1 = 0;

printf(“Enter a positive integer: “);

scanf(“%d”, &num1);

// for loop terminates when n is less than count

for(count1 = 1; count1 <= num1; ++count1)

{

sum1 += count1;

}

printf(“Sum = %d”, sum1);

}

 

Output

Enter a positive integer: 20

Sum = 210

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *