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;
}

Thursday

Chapter - 5 Question & Answers - Class XI - Sumita Arora


Ques(19). Write a short program that asks for your height in centimeters and then convert your height to feet and inches.

Ans.

#include< iostream.h >
#include< conio.h >
void main( )
{
clrscr( );
int a,b,c;
cout << "\n Enter your height in cm";
cin >> a;
b = a/30;
c = a%30;
cout << "\n your height is " << b << "feet and" << c << "inches";
getch( );
}
..............................................................................................................................

Q(20). An electricity board charges according to following rates:
            For the first 100 units - 40 P per unit
            For the next 200 units - 50 P per unit
            Beyond 300 units - 60 P per unit.
            All users are charged meter charge also, which is Rs. 50/-.
            Write a program to read the number of units consumed, and print out the charges.

Ans:

#include< iostream.h >
#include< conio.h >
int main ( )
{
  clrscr( );
long int units, amt_paise = 0;
float amt;
const int met_charge = 50;
cout << " how many units of electricity used ? ";
cin >> units;
if ( units > 300 )
    amt_paise = ( units - 300 )* 60 + 200 * 50 + 100 * 40;
else
    if ( units > 100 )
       amt_paise = ( units - 100 ) * 50 + 100 * 40;
    else
       amt_paise = units * 40;
amt = amt_paise / 100 + met_charge;
cout << " the payable amount is " <<  amt;
getch( );
return 0;
}

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

Q (21). Write a program to read a number n and print n^2, n^3, n^4 and n^5.

Ans:

 #include < iostream.h >
#include < conio.h >
int main()
{
clrscr();
int n;
cout<<"Enter a number n :";
cin>>n;
cout<<"Value of n^2, n^3, n^4 and n^5 is :" ;
cout << (n*n) << "\t" << ( n*n*n ) << "\t" << ( n*n*n*n ) << "\t" << ( n*n*n*n*n );

getch();
return 0;
}


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

Q(22). Write a program to find area of a triangle.

Ans:

#include< iostream.h >
#include< conio.h >
#include< math.h >
int main( )
{
clrscr( );
float a, b, c, s, area;
cout << "enter value of a";
cin >> a;
cout << "enter value of b";
cin >> b;
cout << "enter value of c";
cin >> c;

s = ( a+b+c ) / 2;

area = sqrt ( s * ( s-a ) * ( s-b ) * ( s-c ) ) ;

cout << "area of a triangle is :";
cout << area;
getch( );
return 0;
}

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

Q(23). Write a program to find whether a given number is even or odd.

Ans:

#include< iostream.h >
#include< conio.h >
void main( )
{
clrscr( );
int a;
cout << "Enter any number :" ;
cin >> a;

if ( a%2 = = 0 )
cout << "given Number is even" ;
else
cout << "given number is odd" ;
getch( );
}

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


Ques(24). Write a program to accept three digits and print all possible combinations from these digits. 

Ans:

#include< iostream.h >
#include< conio.h >
void main( )
{
int a[ 3 ];
clrscr( );
cout<<"Enter three digits :"<
cin>>a[ 0 ]>>a[ 1 ]>>a[ 2 ];
for ( int i = 0; i< 3; i++ )
{
for( int j = 0; j < 3;  j++ )
{
for ( int k = 0; k < 3;  k++ )
{
if ( i! = j && i! = k && j! = k )
cout << endl << endl << a[ i ] << a[ j ] << a[ k ];
}
}
}
getch( );
}

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

Q(25) Write a program to convert given inches into its equivalent yards, feet and inches.

Ans:

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

void main( )
{
int in, yrd, ft, r;

cout << " Enter distance/length in inches ";
cin >> in;

yrd = in/ 36;      // calculate yard

r = in % 36;       // remaining inches 
ft = r / 12;      // calculate feet
r = r % 12;      // remaining inches

cout << " \n The distance in inches is " << in ;
cout << " \n The equivalent yard-feet-inches = " << yrd << " yard" << ft << "feet" << r << "inches" ;
getch( );
}

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

Q (26) Program to enter two numbers and print the quotient and remainder

Ans:

#include 
#include 
int main()
{
clrscr();
int x,y,quotient,remainder;
cout << "Enter 2 integers greater than 0 : ";
cin >> x >> y;
quotient = x/y;
remainder = x%y;
cout << "Quotient of " << x << " & " << y << " = " << quotient << "\n";
cout << "Remainder" << " = " << remainder << "\n";
getch();
return 0;
}

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

Q(28). Write a program to:
  1. Print ASCII code for a given digit.
  2. Print ASCII code for backspace.
 Ans:

#include< iostream.h >
#include< conio.h >
void main()
{    clrscr();
     int digit;
    cout << "Enter a digit";
   
    cin >> digit;

        digit = digit + 48;

        cout << "\n ASCII CODE OF ENTERED DIGIT=" << digit;
    cout << "\nASCII code for backspace is " << ( int )( \b );
    getch();
}
 

Wednesday

Program to calculate the factorial of an integer.

#include < iostream.h >
#include < conio.h >
int main( )
{
    clrscr( );
    int i, num, fact = 1;
    cout<<"\nEnter Number :";
    cin>>num;
    i = num;
    while (num)
    {
       fact* = num;
       - - num;
     }

  
   
cout<<" The factorial of "<< i <<" is " << fact <<" \n ";
    return 0;
}