Programs using for loop
Example Program 1:
To find the sum of the digits of the given number using for loop.
#include<stdio.h>
main()
{
int m,i=1,k=0,y,p;
printf("\nEnter any value : ");
scanf("%d",&m);
for(i=1;i<=m;i)
{
y=m%10;
k=k+y;
m=m/10;
}
printf("%d\n\n",k);
}
Output:

Example Program 2:
To print the multiplication table using for loop.
#include<stdio.h>
main()
{
int m,y,k;
printf("\n Enter the required table (m): ");
scanf("%d",&m);
printf("\n");
for(y=1;y<=12;y++)
{
printf("\n%d * %d = %d",m,y,m*y);
}
printf("\n\n table %d is printed \n\n",m);
}
Output:

Share: