Write a C program to add between 2 numbers without using arithmetic operators. or Write
a program to add between 2 numbers without using arithmetic operators in C.
Program in C
Code:
/*Write a C program to add
between 2 numbers without using arithmetic operators. or Write a
program to add between 2 numbers without using arithmetic operators Using
C*/
#include <stdio.h>
int main ()
{
int num1,num2;
printf("Enter the first number\n");
scanf("%d",&num1);
printf("Enter the second number\n");
scanf("%d",&num2);
while (num2 != 0)
{
int carry = num1 & num2;
num1 = num1 ^ num2;
num2 = carry << 1;
}
printf("Addition of two number is %d",num1);
}
Input/Output:
Enter the first number
30
Enter the second number
60
Addition of two number
Write
a C++ program to add between 2 numbers without using arithmetic operators. or Write
a program to add between 2 numbers without using arithmetic operators in C++.
Program in C++
Code:
/*Write a C++
program to add between 2 numbers without using arithmetic operators. or Write
a program to add between 2 numbers without using arithmetic operators using
C++*/
#include <iostream>
using namespace std;
int main ()
{
int num1,num2;
cout<<"Enter the First number:";
cin>>num1;
cout<<"Enter the second number:";
cin>>num2;
while (num2 != 0)
{
int carry = num1 & num2;
num1 = num1 ^ num2;
num2 = carry << 1;
}
cout<<"Addition of two number is "<<num1;
}
Input/Output:
Enter the First number:
25
Enter the second number:75
Addition of two number is 100
Write
a JAVA program to add between 2 numbers without using arithmetic
operators. or Write a program to add between 2 numbers without using
arithmetic operators in Java.
Program in Java
Code:
/*Write a JAVA
program to add between 2 numbers without using arithmetic operators. or Write
a program to add between 2 numbers without using arithmetic
operators using Java*/
import java.util.Scanner;
public class AddTwoNumberWithoutArithmeticOperator {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num1,num2;
System.out.print("Enter the First number\n");
num1=cs.nextInt();
System.out.print("Enter the Second number\n");
num2=cs.nextInt();
while (num2 != 0)
{
int carry = num1 & num2;
num1 = num1 ^ num2;
num2 = carry << 1;
}
System.out.println("Addition of two number is "+num1);
cs.close();
}
}
Input/Output:
Enter the First number
250
Enter the Second number
350
Addition of two number is 600
Write
a PYTHON to add between 2 numbers without using arithmetic operators. or Write
a program to add between 2 numbers without using arithmetic operators in
Python.
Program in Python
Code:
'''Write a Python
program to add between 2 numbers without using arithmetic operators.
or Write a program to add between 2 numbers without using
arithmetic operators using Python '''
print("Enter first number:")
num1=int(input())
print("Enter second number:")
num2=int(input())
while num2 != 0:
carry= num1 & num2
num1= num1 ^ num2
num2=carry << 1
print("Addition of two number is ",num1)
print("Enter first number:")
num1=int(input())
print("Enter second number:")
num2=int(input())
while num2 != 0:
carry= num1 & num2
num1= num1 ^ num2
num2=carry << 1
print("Addition of two number is ",num1)
Input/Output:
Enter first number:
700
Enter second number:
300
Addition of two number is 1000
Most Recommend Questions:-
More Questions:-
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box