multiplication table in c program
Code:
Sample Input and Output:
In this article,we are going to see how we can print multiplication table of any number using C program.Some time such type of problem are asked in college and university level exam's.so those who are college student understand the program logic properly.
In the first line of code we have included header file which is required to use some of the built-in functions like printf and scanf etc Learn more
In the line of code we have declared main function which contains the actual which will helps us to evaluate the result.
In c programming main function is a function from which the execution of program is started i.e. main function is the origin of c program execution,without main function it is not possible to write any c program.
In the next line of code we have declared two variable i,n of type int (Integer).we will use i for iterations purpose and n is to take input number from user of which user want to find multiplication table.I would like to add more thing here i.e. when we declare variable then the compiler allocates the memory location is allocated to all those variable.
In the next line of code we are simply printing the statement "Enter a number:" which will help user to understand that our program is waiting for input,so that they can input any value ,to take user input we have used scanf function with % d format specifier,here we have used % d format specifier because we are storing the input in integer type variable i.e. n.
In the next line we have defined one for loop to calculate multiplication of the number in range of 1 to 10 times.
for eg
4 * 1 = 4(1 times)
4 * 2 = 8(2 times)
4 * 3 = 12(3 times)
.... so on
sample value of n = 4
Let's Understand the for loop iteration by iteration
1st iteration
i =1
printf("Multiplication is %d*%d=%d\n",n,i,(n*i));
Output: Multiplication is 4*1 = 4
2nd iteration
i = 2
printf("Multiplication is %d*%d=%d\n",n,i,(n*i));
Output: Multiplication is 4*2 = 8
3rd iteration
i = 3
printf("Multiplication is %d*%d=%d\n",n,i,(n*i));
Output: Multiplication is 4*3 = 12
.........
........
10th iteration
i = 10
printf("Multiplication is %d*%d=%d\n",n,i,(n*i));
Output: Multiplication is 4*10 = 40
So when the value of i become 10 then the execution will come outside the for loop and we have written getch() which is used to hold the screen.It is mostly used in turbo C Compiler,if you are running in online compiler or any other compiler then just remove the this statement.
The last line of our program is return 0 which is used to tell that the program is normally is executed.
friends.