Customizable training materials to learn C++

Looking for C++ Tutorial Visit Nano teach c++!
  • C++ Variables
    10/07/2014 - 0 Comments
    In C++ Programming language variable is used to store data in memory location. Rules of Declaring variables in C++ Variable name can consist of Capital letters A-Z, lowercase…
  • C++ Inheritance
    07/07/2014 - 0 Comments
    One of the most important concepts in object-oriented programming is that of inheritance. Inheritance is a mechanism of reusing and extending existing classes without modifying…
Nano teach C++ found result for your search here:

C++ Compute the Sum and Average of Two Numbers

This program takes in two integers x and y as a screen input from the user.
The sum and average of these two integers are calculated and outputted using the ‘cout’ command.
Example:
#include<iostream>
using namespace std; 

int main(){ 

    int x,y,sum;
    float average;
    cout << "Enter 2 integers : " << endl;
    cin>>x>>y;
    sum=x+y;
    average=sum/2;
    cout << "The sum of " << x << " and " << y << " is " << sum << "." << endl;
    cout << "The average of " << x << " and " << y << " is " << average << "." << endl;
    system("pause");

}
Program Output:
Enter 2 integers :
12
15
The sum of 12 and 15 is 27.
The average of 12 and 15 is 13.

No comments:

Post a Comment