How to multiply numbers in C-Language
Multiplications of numbers in C-Language
Q:- How to Multiply two constant numbers?
Answer:
- #include <stdio.h>
- int main() {
- const int c=5;
- const int d=2;
- int result;
- result=c*d;
- printf("Multiplication = %d",result);
- return 0;
- }
Code Explanation:
We include preprocessing directory in first line .
We use main() function in second line.
We define two constants variable which can not be change in third and fourth line .
We create an 'result' variable with integer data type in fifth line .
We use 'result' variable to store multiplication of 'c' from 'd' line six.
Print the 'result' variable in seventh line.
On line eight we end the program with return value '0'.
In line number nine we close the curly braces which we open in second line.
output:
Note: If you use constants so you can not change your constant values during runtime.
Q:- How to Multiply two numbers by taking input from user?.
- #include <stdio.h>
- int main() {
- int m,n,ans;
- printf("Enter First Number:");
- scanf("%d",&m);
- printf("Enter Second Number:");
- scanf("%d",&n);
- ans=m*n;
- printf("Your answer is %d",ans);
- return 0;
- }
Code Explanation:
On line one we include preprocessing directory.
In line second we use main() function.
Third line we define three variable in the integer data type.
Fourth line we ask from user to enter first number.
Fifth line we get 1st input integer from the user.
Sixth line we ask from user to enter Second number.
Seventh line we get 2nd inputted integer from the user.
Eighth line we use 'ans' variable to store subtract 'm' from 'n'.
Ninth line we print the 'ans' variable.
Ten line we end the program with return value '0'.
Eleven line we close the curly braces which we open in second line.
Output:
This is the code for Multiplication of two numbers .You can add only few lines of similar code so you can multiply more than two numbers.