Friday

Question-Answers-Chapter-6-Computer Science with C++ By Sumita Arora

Q(28). Write a program which will raise any number X to a positive power n. Obtain values of X and n from user.

Ans:

#include< iostream.h >
#include< conio.h >
int main( )
{
  clrscr( );
  int X, n, result;
cout << "Enter value of X :" ;
cin >> X;
cout << "Enter value of n :" ;
cin >> n;
result = pow (X, n);
cout << "Result is :";
cout << result;
getch( );
return 0;
}

.................................................................................................

Q(29) Write a C++ program to input principal amount and time. If time is more than 10 years, calculate the simple interest with rate 8%. otherwise calculate it with rate 12% per annum.

Ans:

#include< iostream.h >
#include< conio.h >
int main( )
{
clrscr( );
int t ;
float p, SI;
cout << "Enter Principal Amount :";
cin >> p;
cout << "Enter time :";
cin >> t;
SI = ( t>10 ) ? ( p*8*t )/100 : ( p*12*t )/100;
cout << "Simple Interest is :";
cout << SI;
getch( );
return 0;
}

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.