#include <stdio.h>
/* C program to print multiplication table of a number using while loop */
int main()
{
int j = 1,n;
printf("Enter Any Number\n");
scanf("%d",&n);
printf("\n Table of %d is:",n);
while(j <= 10)
{
printf(" %d ", n*j);
j++;
}
printf("\n");
return 0;
}
Output:
Enter Any Number
5
Table of 5 is:
5 10 15 20 25 30 35 40 45 50
Program Explanation:
In the above program variable j is declared as integer variable and initialized to number 1.
variable n is also declared as integer whose table we want to find out.
printf("Enter Any Number\n");
prompt the user "Enter Any number" control jumps to
scanf("%d",&n); function and wait for input.
User inputs/enteres number 5 which is get stored(scaned)in variable n.
printf("\n Table of %d is:",n);
displays--> Table of 5 is:
control jumps to while loop and test the condition while(j<=10).
i.e. while(1<10) which results in true.
Then printf("%d ", n*j); statement inside body of loop executes and display value of n*j .i.e. 5 .
The value of j is incremented by 1, now j becomes 2 i.e. j=2.
control again jumps to while and test the condition which is true and execute the body of loop
shows output 10 after that value of j is incremented by 1.
the process continues while the value of j is less than or equal. (while (j<=10))