A Table of Cube, Square and Fourth Numbers – C++

A program I wrote in labs in uni, as a set task. It prompts the user to enter a number where it then prints out in a table starting from 1 up to the number entered the user entered. It also includes the cubed, squared and fourth number. 

#include <iostream>
#include <cmath>
#include <conio.h>
#include <iomanip>

using namespace std;

int main()
{
	int n;
	cout << "Please enter an interger" << endl;
	cin >> n;
    
	cout << "Value" << setw(10) << "Square" << setw(12) << "Cube" << setw(13) << "Fourth" << setw(10) << endl;
    
	for(int run=1; run<=n; run++)
	{
        
		cout << run << setw(10) << left;
		cout << pow (run, 2) << setw(10) << left;
		cout << pow (run, 3) << setw(10) << left;
		cout << pow (run,4) << setw(10) << left << endl;
        
	}//for 
    
    _getch();
	return 0;
}//main

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s