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;
}
#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:
Output:
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
Post a Comment