5.c++ program to get 2 integer numbers and display their sum

 





Introduction to fundamental Data types:
        Fundamental data types are predefined data types available with C++.There are five fundamental data types in C++:
                                - char
                                - int
                                - float
                                - double
                                - void.
             Actually, these are the keywords for defining the data types.

(1) int data type:

        Integers are whole numbers without any fraction. Integers can be positive or negative. Integer data types accepts and returns only integer numbers. if a variable is declared as an int, C++ compiler allows storing only integer values into it. if you try to store a fractional value in an int type variable it will accept only the integer portion of the fractional value..
   
// C++ program to get 2 integer numbers and display their sum

INPUT:

#include<iostream>

using namespace std;

int main()

{

    int n1,n2,sum;

    cout<<"\n Enter Number 1:";

    cin>>n1;

    cout<<"\n Enter Number 2:";

    cin>>n2;

    sum = n1+n2;

    cout<<"\n The Sum of "<<n1<<" and " <<n2<<" is "<<sum<<endl;

}

            In the above program, there are three variables declared. n1,n2 and sum. All these three variables are declared as integer types. so, three different integer values can be stored in these variables.

        The variable n1 and n2 are used to store the values that are obtained from the user during the execution of the program, whereas the variable sum is used to store the processed (resultant) value.

        During the execution of the above program, line numbers 6 and 8 prompt the user to Enter number 1 and number 2.


OUTPUT:





Comments