C++ program to read number n and print n2, n3, n4 and n5.

Q21. Write a program to read a number n and print n2, n3, n4 and n5.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr()

 

//Main function

void main()

{

int n,n2,n3,n4,n5;

clrscr();  //for clear screen

cout<<“\n Enter a number: “;

cin>>n;

n2=n*n;

n3=n*n*n;

n4=n*n*n*n;

n5=n*n*n*n*n;

cout<<“\n The square of given number is: “<<n2;

cout<<“\n The cube of given number is: “<<n3;

cout<<“\n The quad of given number is: “<<n4;

cout<<“\n The penta of given number is: “<<n5;

getch();  //To hold the output screen

}

//End of main()

 

Output:

Enter a number: 5

 

The square of given number is: 25

The cube of given number is: 125

The quad of given number is: 625

The penta of given number is: 3125

Leave a Reply

Your email address will not be published. Required fields are marked *

31 Views
%d bloggers like this: