In this tutorial, we will discuss the concept of C program to find the sum of two numbers without using arithmetic operators
In this post, we will learn how to make the addition of two number using without arithmetic operator in C programming language
This program allows finding the addition of two numbers entered by the user – using for loop without arithmetic operator
#include <stdio.h> #include <stdlib.h> int main() { int num1,num2,i; //Variable declaration printf("Enter the first number: "); scanf("%d",&num1); printf("Enter the second number: "); scanf("%d",&num2); for(i=0; i<num2; i++){ num1++; } printf("Sum of two numbers : %d ",num1); getch(); return 0; }
When the above code is executed, it produces the following results
Enter the first number: 26 Enter the second number: 84 Sum of two numbers : 110
Methods
This program allows finding the addition of two numbers entered by the user using while loop without arithmetic operator
#include <stdio.h> #include <stdlib.h> int main() { int num1,num2,i; //Variable declaration printf("Enter the first number: "); scanf("%d",&num1); printf("Enter the second number: "); scanf("%d",&num2); while(num2 != 0){ int num3=(num1 & num2); num1=num1^num2; num2=num3<<1; } printf("Sum of two numbers is:%d ",num1); getch(); return 0; }
When the above code is executed, it produces the following results
Enter the first number: 125 Enter the second number: 65 Sum of two numbers : 190
Methods
This program allows finding the addition of two numbers entered by the user using for loop without arithmetic operator
#include <stdio.h> #include <stdlib.h> int add(int ,int); //function protottype or diclaration int main() { int n1,n2; //Variable declaration printf("Enter the first number: "); scanf("%d",&n1); printf("Enter the second number: "); scanf("%d",&n2); printf("Sum of two numbers is: %d",add(n1,n2)); //function call getch(); return 0; } int add(int num1, int num2){ //function definition 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: 123 Enter the second number: 234 Sum of two numbers : 357
Method
This program allows finding the addition of two numbers entered by the user using while loop without arithmetic operator
#include <stdio.h> #include <stdlib.h> int add(int ,int); //function prototype int main() { int n1,n2; //Variable declaration printf("Enter the first number: "); scanf("%d",&n1); printf("Enter the second number: "); scanf("%d",&n2); printf("Sum of two numbers is: %d",add(n1,n2)); //function call getch(); return 0; } int add(int num1, int num2){ //function definition int i; 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: 300 Enter the second number: 250 Sum of two numbers : 550
Method
Similar post
C++ program to find the sum of two numbers without using arithmetic operators
Java program to find the sum of two numbers without using arithmetic operators
Python program to find the sum of two numbers without using arithmetic operators
Suggested for you
User-defined function in C language
Input-output function in C language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…
View Comments