Multiplication of two numbers
Table of Contents
In this tutorial, we will discuss the Multiply two integers in C language
In this post, we are going to learn how to find multiplication of two numbers via different 6 ways in C language
Program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1=10,num2=15,product;
product=num1*num2;
printf("product of %d and %d : %d",num1,num2,product);
getch();
return 0;
}
When the above code is executed, it produces the following result
product of 10 and 15 : 150
Approach
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,product;
printf("Enter two numbers: ");
scanf("%d %d",&num1,&num2);
product=num1*num2;
printf("product of %d and %d : %d",num1,num2,product);
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter two numbers:25 30 product of 25 and 30: 750
Approach
Program 3
#include <stdio.h>
#include <stdlib.h>
int main()
{
int multiply(int,int),num1,num2,product;
printf("Enter the first number!\n");
scanf("%d",&num1);
printf("Enter the second number!\n");
scanf("%d",&num2);
product=multiply(num1,num2);
printf("Product of %d and %d is: %d",num1,num2,product);
getch();
return 0;
}
int multiply(int n1,int n2)
{
return(n1*n2);
}
When the above code is executed, it produces the following result
Enter the first number! 45 Enter the second number! 50 Product of 45 and 50 is: 2250
Approach
Program 4
#include <stdio.h>
#include <stdlib.h>
int multiply(int,int);
int main()
{
int num1,num2,product;
printf("Enter the first number!\n");
scanf("%d",&num1);
printf("Enter the second number!\n");
scanf("%d",&num2);
product=multiply(num1,num2);
printf("Product of %d and %d is: %d",num1,num2,product);
getch();
return 0;
}
int multiply(int n1,int n2)
{
if(n2==1)
return n1;
else
return(n1+multiply(n1,n2-1));
}
When the above code is executed, it produces the following result
Enter the first number! 35 Enter the second number! 70 Product of 45 and 50 is: 2450
Approach
Program 5
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,*ptr1,*ptr2,multiple;
//read two user input integer values for variable num1,num2
printf("Enter first number\n");
scanf("%d",&num1);
printf("Enter second number\n");
scanf("%d",&num2);
ptr1=&num1;
ptr2=&num2;
//assign address of variable num1, num2 to pointers ptr1 and ptr2
multiple=*ptr1 * *ptr2;
printf("Product of the numbers %d and %d= %d",num1,num2,multiple);
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter first number! 15 Enter second number! 22 Product of the numbers 15 and 22 : 330
Approach
Program 6
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2;//declaring two integer variable
int product=0;//declaring and initializing product as zero
printf("Enter two integer : \n");
scanf("%d%d",&num1,&num2);
//read the two input values from the user
while(num2 != 0){
product+=num1;
num2--;
}
printf("\nProduct of two numbers= %d",product);
getch();
return 0;
} When the above code is executed, it produces the following result
Enter two integer: 12 13 product of two numbers=156
Suggested for you
Data type in C language
Variable in C language
Similar post
Find product of two numbers in Java language|5ways
Find product of two numbers in C++ language|6ways
Find product of two numbers in Python language|4ways
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.