Problem statement:- Program to compute Multiply two numbers without using multiplication(*) operator
Input Data:- a1,a2
Output Data:-sum
Additional Data:-i
Program in C
Here is the source code of the C Program to Multiply two numbers without using the multiplication(*) operator.
Code:
#include<stdio.h>
int main()
{
int a1,a2,sum=0,i;
// Get the two number
printf("Enter the two numbers :\n");
scanf("%d %d",&a1,&a2);
//compute the multiplication
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
//Display multiplication value
printf("The multiplication of %d and %d is %d \n",a1,a2,sum);
}
Input/Output:int main()
{
int a1,a2,sum=0,i;
// Get the two number
printf("Enter the two numbers :\n");
scanf("%d %d",&a1,&a2);
//compute the multiplication
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
//Display multiplication value
printf("The multiplication of %d and %d is %d \n",a1,a2,sum);
}
Enter the two numbers :
4
5
The multiplication of 4 and 5 is 20
Program in C++
Here is the source code of the C++ Program to Multiply two numbers without using the multiplication(*) operator.
Code:
#include<iostream>
using namespace std;
int main()
{
int a1,a2,sum=0,i;
cout<<"Enter the two numbers :\n";
cin>>a1;
cin>>a2;
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
cout<<"The multiplication of "<<a1<<" and "<<a2<<" is "<<sum;
}
Input/Output:using namespace std;
int main()
{
int a1,a2,sum=0,i;
cout<<"Enter the two numbers :\n";
cin>>a1;
cin>>a2;
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
cout<<"The multiplication of "<<a1<<" and "<<a2<<" is "<<sum;
}
Enter the two numbers :
3
9
The multiplication of 3 and 9 is 27
Program in Java
Here is the source code of the Java Program to Multiply two numbers without using the multiplication(*) operator.
Code:
import java.util.Scanner;
public class P4 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int a1,a2,sum=0,i;
System.out.println("Enter the two numbers :");
a1=cs.nextInt();
a2=cs.nextInt();
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
System.out.println("The multiplication of "+a1+" and "+a2+" is "+sum);
cs.close();
}
}
Input/Output:public class P4 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int a1,a2,sum=0,i;
System.out.println("Enter the two numbers :");
a1=cs.nextInt();
a2=cs.nextInt();
for(i=1;i<=a1;i++)
{
sum=sum+a2;
}
System.out.println("The multiplication of "+a1+" and "+a2+" is "+sum);
cs.close();
}
}
Enter the two numbers :
4
10
The multiplication of 4 and 10 is 40
Program in Python
Here is the source code of the Python Program to Multiply two numbers without using the multiplication(*) operator.
Code:
num1=int(input("Enter the First numbers :"))
num2=int(input("Enter the Second number:"))
sum=0
for i in range(1,num1+1):
sum=sum+num2
print("The multiplication of ",num1," and ",num2," is ",sum)
Input/Output:num2=int(input("Enter the Second number:"))
sum=0
for i in range(1,num1+1):
sum=sum+num2
print("The multiplication of ",num1," and ",num2," is ",sum)
Enter the two numbers :
4
5
The multiplication of 4 and 5 is 20
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box