7. Program that inputs a number from user and displays its square and cube.

Chapter 4: 

Input And Output

Programming Exercise

Problem # 7:

Write a program that inputs a number from user and displays its square and cube.

Solution:

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
    int number, square, cube;
    cout<<"Enter a number : ";
    cin>>number;
    square = pow(number,2);
    cube = pow(number,3);
    cout<<"Square : "<<square<<endl;
    cout<<"Cube : "<<cube<<endl;
    return 0;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

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

Previous Post:
6. Program that inputs age in years and display age in days and months.

Comments