C Program to multiply two numbers in C language

How to multiply numbers in C-Language

Multiplications of numbers in C-Language


Q:- How to Multiply two constant numbers?



C Program to multiply two numbers in C language





Answer:

  1. #include <stdio.h>
  2. int main() {
  3.        const int c=5;
  4.        const int d=2;
  5.        int result;
  6.        result=c*d;
  7.        printf("Multiplication = %d",result); 
  8.        return 0;
  9. }
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:

C Program to multiply two numbers in C language





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?.



C Program to multiply two numbers in C language





Answer:

  1. #include <stdio.h> 
  2. int main() {
  3.        int m,n,ans;
  4.        printf("Enter First Number:");
  5.        scanf("%d",&m);
  6.        printf("Enter Second Number:");
  7.        scanf("%d",&n);
  8.        ans=m*n;
  9.        printf("Your answer  is %d",ans);
  10.        return 0;
  11. }
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:

C Program to multiply two numbers in C language







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.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.