If you searching for Addition of two numbers in c | c++ and java then you are at the right article.
Table of content
Programming pre-requisitests for adding two numbers
- Data-types in c | c++ and java.
- Input and output operation in c | c++ and java.
- Assignment operator in c | c++ and java.
- Unary addition in c | c++ and java.
Addition of two numbers in c
#include<stdio.h>
int main(int argc, char const *argv[])
{
int number1,number2;
//input the number
printf("Addition of two numbers using c\nEnter two numbers\n");
scanf("%d%d",&number1,&number2);
int sum=number1+number2;
printf("\nSum of %d and %d is: %d\n",number1,number2,sum);
return 0;
}
Addition of two numbers in c++
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int number1,number2;
cout<<"Addition of two numbers in c\n";
cout<<"Enter two numbers\n";
int sum=0;
cin>>number1>>number2;
sum=number1+number2;
cout<<"Sum of"<<number1<<" and "<<number2<<" is "<<sum<<endl;
return 0;
}
Addition of two numbers in java
import java.util.Scanner;
public class AdditionOfTwoNumbersInJava {
public static void main(String[] args) {
System.out.println( "Addition of two numbers in java" );
System.out.println( "Enter two numbers" );
int number1,number2;
Scanner stdin=new Scanner( System.in );
number1=stdin.nextInt();
number2=stdin.nextInt();
int sum=0;
sum=number1+number2;
System.out.println("Sum of "+number1+" and "+number2 + " is "+sum);
}
}
People also read
- Armstrong number in C | C++ and Java
- Palindrome in C | C++ and Java
- Linear Search in C | C++ and Java
- Binary Search Algorithm
- Factorial program in C | C++ and Java
- Odd even program in c | c++ and java
- Bubble sort in c | c++ and java
- Addition Wiki
- Reverse a number in c | c++ and Java