Example on for loop:

Example on for loop:

/*wap to print natural numbers from 1 to n */

#include
main()
{
int i,n;

printf("\nEnter the value for n ");
scanf("%d",&n);

for(i=1;i<=n;i++)
    {
       printf("%d\n",i);
     }

}

In the above program natural numbers from 1 to n will be printed. Suppose the value of n is 5 then output will be as follows,
1
2
3
4
5



Comments