27. Program that displays the following output: Number Square Cube

Chapter 4: 

Input And Output

Programming Exercise

Problem # 27:

Write a program that displays the following output:
    Number    Square    Cube
    1        1        1
    2        4        8
    3        9        27
    4        16        64
    5        25        125

Solution:

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
    cout<<"Number \t Square \t Cube"<<endl;
    cout<<"1 \t 1 \t 1"<<endl;
    cout<<"2 \t 4 \t 8"<<endl;
    cout<<"3 \t 9 \t 27"<<endl;
    cout<<"4 \t 16 \t 64"<<endl;
    cout<<"5 \t 25 \t 125"<<endl;
    getch();
    return 0;
}

Let me know in the comment section if you have any question.

Previous Post:
26. Program that inputs a number and displays its corresponding ASCII code.

Comments