C Programming language

C Program example: Input a number n and print multiplication from 1 to n
Previous Home Next

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.

/*input a no and print the following 1*2*3*4*5*6......*n */

void main()
	int n,i,f=1;
	printf("Enter the no ");
	printf("The multiplication from 1 to %d =%d",n,f);

Enter the no3
The multiplication from 1 to3=6

Previous Home Next