Learn C with example
Input a Number and Print The Following 1*2*3*4*5*6......*n
In this example we are going to print multiplication
from 1 to n .Here n is number which user will enter at run time.
To find multiplication we are using for loop.
for loop will iterate from 1 to n and multiply values. Here we have define a
variable f and assign 1 into f .In for loop we multiply the
values with f and assign the values into f .When for loop will end
then the value of multiplications of values from 1 to n will store
into f. At last we print value of the f .This is final result.
Source Code Of Example
/*input a no and print the following
1*2*3*4*5*6......*n */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,f=1;
clrscr();
printf("enter the no");
scanf("%d",&n);
for(i=1;i<=n;i++)
f=f*i;
printf("The multiplication from 1 to %d =%d",n,f);
getch();
}
|
Output Of Example
enter the no3
The multiplication from 1 to3=6 |