multiply

C program to multiply two numbers without using arithmetic operator

C program to multiply two numbers without using arithmetic operator

problem – C program to multiply two numbers without using arithmetic operator

 

In this tutorial, we will discuss the concept of  multiplying two numbers without using arithmetic operator in C language. 

In this post, we will learn how to get the product of two number without arithmetic operator in C programming language

multiply two numbers without using arithmetic operator

C program to find the product of two numbers

Using for loop – Program 1

This program is used to find the multiplication of two numbers entered by the user – using for loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>
int add(int n1, int n2);

int main()
{
    int n1,n2,product=0,i;//variable declaration
    printf("Enter the first  number: ");
    scanf("%d",&n1);  //Takes input from the user for n1
    printf("Enter the first  number: ");
    scanf("%d",&n2);   //Takes input from the user for n2
    for(i=0; i<n2; i++){
    product=add(product,n1);
}
printf("product of %d and %d are: %d\n",n1,n2,product);
    getch();
    return 0;
}

int add(int num1,int num2){
    int i;
for(i=0; i<num2; i++)
   num1++;
return num1;
}

When the above code is executed, it produces the following results

Enter the first number: 12
Enter the second number:23
product of 12 and 23 are: 276

Using while loop – Program 2

This program is used to find the multiplication of two numbers entered by the user – using while loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>
int add(int n1, int n2);

int main()
{
    int n1,n2,product=0,i;
    printf("Enter first  number: ");
    scanf("%d",&n1);  //Takes input from the user for n1
    printf("Enter first  number: ");
    scanf("%d",&n2);   //Takes input from the user for n2
    for(i=0; i<n2; i++){
    product=add(product,n1);
}
printf("product of %d and %d is: %d\n",n1,n2,product);
    getch();
    return 0;
}

int add(int num1,int num2){
    while(num2 != 0){
int num3=(num1 & num2);
num1=num1^num2;
num2=num3<<1;

}
return num1;
}

 

When the above code is executed, it produces the following results

Enter the first number: 12
Enter the second number:24
product of 12 and 23 are: 288

 

Similar program

Java program to multiply two numbers without using arithmetic operator

C++ program to multiply two numbers without using arithmetic operator

Python program to multiply two numbers without using arithmetic operator

Java program to multiply two numbers using method

C++ code to multiply two numbers using function

Python program to multiply two numbers using function

C code to multiply two numbers using function

C# program to multiply two numbers using function

PHP program to multiply two numbers

C# program to multiply two numbers

JavaScript program to multiply two numbers

 

 

Suggested for you

for loop in C language

while loop in C language

Function in C language

User defined function in C language

input output function in C language

Datatype in C language

Variable in C language

 

Python program to compute the sum of digits in a given numbers
C++ program to multiply two numbers without using arithmetic operator
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago