Loop Control Structures – For Loop – Theory and Programs [Learn to code]

Understanding for loop. Learn syntax for For-Loop and different programs on Loop Control Structures.

  • 032. Write a program to print table of a given number n in C language
    #include<stdio.h>
    #include<conio.h>
    main()
    { 
     int i,n;
     clrscr();
     printf("Enter number : ");
     scanf("%d",&n);
     for(i=1;i<=10;i++)
    	printf("%d X %d = %dn",n,i,n*i);
     getch();
    }
  • 033. Write a program to print sum of given first n numbers in C language
    #include<stdio.h> 
    #include<conio.h>
    main()
    {
     int n,newn,i,sum=0;
     clrscr();
     printf("Enter number : ");
     scanf("%d",&n);
     printf("Numbers entered....n");
     for(i=1;i<=n;i++)
     {
    	scanf("%d",&newn);
    	sum=sum+newn;
     }
     printf("Sum of given n digits is... %d",sum);
    }

033. Write a program to print sum of given first n numbers in C language

#include<stdio.h> 
#include<conio.h>
main()
{
 int n,newn,i,sum=0;
 clrscr();
 printf("Enter number : ");
 scanf("%d",&n);
 printf("Numbers entered....\n");
 for(i=1;i<=n;i++)
 {
	scanf("%d",&newn);
	sum=sum+newn;
 }
 printf("Sum of given n digits is... %d",sum);
}