In this article, we will discuss the concept of the Sum of two integer using without + operator in C
In this post, we are going to learn how to write a program to find the sum of two numbers using without plus operator in C programming language
The program allows the user to enter two integers and then calculates the sum of given numbers using minus operator in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int num1,num2; printf("Enter two number for addition:\n"); scanf("%d %d",&num1,&num2); //get input from user for num1 and num1 int result =num1-(-num2); //calculate sum of two numbers using minus printf("Sum of two numbers %d and %d is: %d",num1,num2,result); //Display result on the screen getch(); return 0; }
When the above code is executed, it produces the following result
Enter two number for addition: 1200 2400 Sum of two numbers 1200 and 2400 is: 3600
The program allows the user to enter two integers and then calculates the sum of given numbers using for loop with function in C language
Program 2
#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); //get input from user for n1 printf("Enter the second number: "); scanf("%d",&n2); //get input from user for n2 printf("Sum of two numbers is: %d",add(n1,n2)); //Calling the function to produce output 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 result
Enter the first number: 250 Enter the second number: 340 Sum of two numbers is: 590
The program allows the user to enter two integers and then calculates the sum of given numbers using while loop with function in C language
Program 3
#include <stdio.h> #include <stdlib.h> int add(int ,int); int main() { int n1,n2; printf("Enter the first number: "); scanf("%d",&n1); //get input from user for n1 printf("Enter the second number: "); scanf("%d",&n2); //get input from user for n2 printf("Addition of two numbers is: %d",add(n1,n2)); //Calling the function to produce output on the screen getch(); return 0; } int add(int num1, int num2){//function definition int i; i=0; while(i<num2){ num1++; i++; } return num1; }
When the above code is executed, it produces the following result
Enter the first number: 135 Enter the second number: 531 Addition of two numbers is: 666
The program allows the user to enter two integers and then calculates the sum of given numbers using increment and decrement operator
Program 4
#include <stdio.h> #include <stdlib.h> int add(int ,int); int main() { int n1,n2; printf("Enter the first number: "); scanf("%d",&n1); //get input from user for n1 printf("Enter the second number: "); //get input from user for n2 scanf("%d",&n2); printf("adition of two numbers is: %d",add(n1,n2)); //Calling the function and display result on the screen getch(); return 0; } int add(int n1,int n2){//function definition while(n1>0){ n2++; n1--; } while(n1<0){ n2--; n1++; } return n2; }
When the above code is executed, it produces the following result
Enter the first number: 455 Enter the second number: 345 Addition of two numbers is: 800
The program allows the user to enter two integers and then calculates the sum of given numbers using bitwise operator in C language
Program 5
#include <stdio.h> #include <stdlib.h> int add(int ,int);//function prototype int main() { int n1,n2; printf("Enter the first number: "); scanf("%d",&n1); printf("Enter the second number: "); scanf("%d",&n2); printf("Addition of two numbers is: %d",add(n1,n2)); //Calling the function to produce output getch(); return 0; } int add(int num1,int num2){//function definition while(num2!=0){ int brw =num1 & num2; num1=num1^num2; num2=brw<<1; } return num1; }
When the above code is executed, it produces the following result
Enter the first number: 123 Enter the second number: 321 Addition of two numbers is: 444
Suggested for you
Function in C language
Similar post
Subtract two numbers in C language
Subtract two numbers using function in C language
Subtract two numbers using recursion in C language
Find addition of two numbers in C language
Find addition of two numbers in C language using pointer
Find addition of two numbers in C language using function
Find addition of two numbers in C using recursion
Find addition of two numbers in C without Arithmetic operator
Find addition of natural numbers in C language
Find addition of natural numbers in C language using recursion
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…