addition

Sum of two integer using without + operator in C

Sum of two integer using without + operator in C

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

Code to find the Addition of  two numbers 

Sum of two integer

Add two integer using with – operator

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

Add  two integer using for loop with function

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

 

Add  two integer using while loop with function

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

 

Add  two integer  using increment, decrement operator

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

 

Add  two integer using bitwise operator

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

Operator in C language

Data type in C language

variable in C language

if statements in C language

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

 

Program to sum of two integer using without + operator in Java
Python code to Add two integer using without + 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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago