Skip to main content

Write a C C++ program to find sum of two numbers


Flowchart

Flowchart to add two numbers

Coding in C

#include <stdio.h>
int main()
{
    int n1,n2,sum;
    printf("Enter number1: ");
    scanf("%d",&n1);
    printf("Enter number2: ");
    scanf("%d",&n2);
    sum=n1+n2;
    printf("Sum of numbers = %d",sum);
    return 0;
}

Coding in C++

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,sum;
    cout<<"Enter number1: ";
    cin>>n1;
    cout<<"Enter number2: ";
    cin>>n2;
    sum=n1+n2;
    cout<<"Sum of numbers = "<<sum;
    return 0;
}

Output

Write a C++ program to find sum of two numbers