My Visitors

Flag Counter

Tuesday 13 November 2012

Input and Output

Q1.Write a program that prints a text of 4 lines consisting of character,integer values and floating-point values using count statement.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Asia 146 3.96"<<endl;
cout<<"Zain 148 3.98"<<endl;
cout<<"Iman 150 3.36"<<endl;
cout<<"Arman 152 3.33"<<endl;

getch();
}

Q2.Write a programm that inputs of sphere from the user.Calculates its volume and surface area using the formula Area=4πR*R and circumference=4/3πR*R*R where π=3.14.

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 float r,area,cir;
 cout<<"enter radius:";
 cin>>r;
 area=4.0*3.14*3.14;
 cir=(4.0/3.0)*3.14*r*r*r;
 cout<<"area is="<<r<<endl;
 cout<<"circumference is="<<cir;

getch();
}

Q3.Write a program to find out the area of triangle when three sides a,b and c of the triangle are given.Use appropriate statements to print the values of a,b and c from the keyboard.Formula for the area of triangle is area=(s(s-a)(s-b)(s-c))1/2 where s=(a+b+c)/2


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c;
double s,area;
cout<<"enter side a:";
cin>>a;
cout<<"enter side b:";
cin>>b;
cout<<"enter side c:";
cin>>c;
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"Area of triangle is="<<area;


getch();
}

Q4.write a program that inputs miles from the user and convert miles into kilometers.One mile is equal to 1.609 kilometer.
#include<iostream.h>
#include<conio.h>
void main()

{
        clrscr();
        float m,k;
        cout<<"input in miles;";
        cin>>m,
        k=m*1.609;
     cout<<"Miles into Kilometers;"<<k;

 getch();

}

Q5.Write a program that inputs 4 numbers and calculates the sum,average,and product of all the numbers.


#include<iostream.h>
#include<conio.h>
void main()


{
clrscr();
 int a,b,c,d,sum,product;
 float avg;
 cout<<"enter 1st number:";
 cin>>a;
 cout<<"enter 2nd number:";
 cin>>b;
 cout<<"enter 3rd number:";
 cin>>c;
 cout<<"enter 4th number:";
 cin>>d;
 sum=a+b+c+d;
 product=a*b*c*d;
 avg=sum/4.0;
 cout<<"sum of all number:"<<sum<<endl;
 cout<<"average:"<<avg<<endl;



getch();
}





Q6.Write a program that inputs age in years and diplays age in days and month.

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

void main()

{
     int age,months,days;
     clrscr();
     cout<<"Enter age in years";
     cin>>age;
     months=age*12;
     days=age*365;
     cout<<"Age in months"<<months<<endl;
     cout<<"Age in days"<<days;
    
getch();


}



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

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int n,sq,cube;
 cout<<"input a number:";
 cin>>n;
 sq=n*n;
 cube=n*n*n;
 cout<<"square is="<<sq<<endl;
 cout<<"cube is="<<cube;

 getch();

}

Q8.Write a program that inputs total pages of a book,number of pages a person reads in one day and number of days a person has read the book.It displays number of pages that have been read and number of pages remaining.

#include<iostream.h>
#include<conio.h>
void main()

{
clrscr();
 int pages,pages_daily,days,remainig,completed;
 cout<<"Enter total pages of book";
 cin>>pages;
 cout<<"How many pages you read daily?";
 cin>>pages_daily;
 cout<<"How many days you read the book?";
 cin>>days;
 completed=days*pages_daily;
 remaining=pages-completed;
 cout<<"You have read"<<completed<<"pages"<<endl;
 cout<<"Remaining pages are"<<remaining;

getch();
}


Q9.A car can travel 5.3 miles in 1 liter.Write a program that inputs petrol in liters and displays how much distance the car can cover using the avilable petrol.


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float p,d;
cout<<"inputs petrol in liters:";
cin>>p;
d=p*5.3;
cout<<"car covers  distance using available petrol:"<<d;
getch();
}


Q10.Write a program that inputs total number of student in a class and fee per student.It displays total fee collected from the class.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int s,f,fees;
cout<<"total number of students in class:";
cin>>s;
cout<<"fee per students:";
cin>>f;
fees=f*s;
cout<<"total fee collected from the class:"<<fees;

getch();
}


Q11.Write a program that inputs temperature from the user in Fahrenheit and converts it into Celsius degree using formula C=5/9(F-32).

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

float cel,faren;
cout<<"enter tempe in farenheit:";
cin>>faren;
cel=5.0/9.0*(faren-32);
cout<<"temperature in celcus is ="<<cel;

getch();
}


Q12.Write a program that inputs a 3-digit number and displays its digit in separate three lines.For example if the user enters 123,the program displays the output as follows.

1
2
3

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


void main()

{

clrscr();
     int n,a,b,c;

    cout<<"Enter a 3-digit number";
      cin>>n;
       a=n/100;
       n=n%100;
       b=n/10;
      c=n%10;
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;

getch();


}


Q13.write a program to show following output using one cout statement:

1        2          3           4          5

6         7         8           9          10


#include<iostream.h>

#include<conio.h>

void main()

{
     clrscr();

     cout<<"1 2 3 4 5 \n6 7 8 9 10";


getch();


}


Q14.Write a program to calculate the volume(v) of a cube by taking measures from the user.(Formula:V=length*width*height)

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

void main(0

{
     clrscr();
    float leng,wid,ht,v;
    cout<<"Enter lenght:";
    cin>>leng;
    cout<<"Enter width:";
    cout<<"Enter height:";
    cin>>ht;
   v=leng*wid*ht;
   cout<<"Volume of cube"<<v;

getch();

}


Q15.Write a program that inputs the x,y coordinates for two points and computes the distance between two points using the formula:Distance=((x*x-x1)2+(y*y-y1)2)1/2..


#include<iostrea.m>
#include<conio.h>
#include<iomanip.h>
#include<math.h>

void main()
{

    clrscr();

      double x1,y1,x2,y2
     cout<<"Enter first point x1 and y1:";
     cin>>x1>>y1;
     cout<<"Enter second x2 and y2:";
     cin>>x2>>y2;

 double distance=pow(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2),0.5);
cout<<"Distance of two points is:"<<distance;

getch();

}


Q16.Write a program to swap the values of three variable with using fourth variable ..

#include<iostream.h>
#include<conio.h>
void main()
{
       clrscr();
       int a,b,c,temp;
     cout<<"enter the first number:";
     cin>>a;
    cout<<"enter the 2nd number:";
     cin>>b;
    cout<<"enter the 3rd number:";
    cin>>c;
   cout<<"you input the numbers "<<a<<"and"<<b<<"and"<<c<<endl;
         temp=a;
          a=b;
          b=temp;
          b=c;
         c=temp;
   cout<<"the value after swapping are"<<a<<"and"<<b<<"and"<<c;

 getch();

   }


Q17.Write a program that calculates the arc of length of a convex lens by taking radius of arc and angle made by arc.(Formula:length=radius*angle)...



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


void main()


{


 clrscr();
 float length,radius,angle;
 cout<<"Enter radius:";
 cin>>radius;
 cout<<"Enter angle:";
 cin>>angle;
 length=radius*angle;
 cout<<"Length="<<length;



getch();


}



Q18.Write a program that inputs pounds from the user and converts it into kilograms..


#include<iostrea.h>
#include<conio.h>

void main()

{

clrscr();
double pounds,kilograms;
cout<<"Enter the number of pounds:";
cin>>pounds;
kilograms=pounds/2.205;
cout<<pounds<<"pounds="<<kilograms<<kilograms\n";

getch();

}



Q19.Write a program that computes the area of a sector of a circle when theta is the angle in radians between the radii...


#include<iostrea.h>
#include<conio.h>

{
  clrscr();
  double theta,r,area;
  cout<<"Enter length of radii and angle in radians between them:";
  cin>>r>>theta;
  cout<<"The area of sector is"<<area<<endl;

getch();

}
Q20.Write a program that reads a positive number and then computes the logrithm of that value to the base 2.....

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
double n;
double result;
clrscr();
cout<<"Enter a number:";
cin>>n;
result=log(n)/log(2.0);
cout<<"log of number :"<<n<<"to the base 2 is "<<result<<endle;

getch();
}

Q21.Write a program to enter a letter and display the next two letters.....



#include<iostream.h>
#include<conio.h>
void main()
{
  char a;
  clrscr();
  cout<<"Enter a letter:";
  cin>>a;
  int n=a;
  int n1=n+1;
  int n2=n1+1;
 char c1=n1;
 char c2=n2;
 cout<<"next two letters:"<< c1 <<  "and"  <<c2;

getch();
}


Q22.Write a program that inputs five-digit number through the keyboard and calculates the sum of its digit....

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

void main()
{
 int a,b,c,d,sum,n;
 clrscr();
 cout<<"enter five digit number:";
 cin>>n;
 a=n/10000;
 n=n%10000;
 b=n/1000;
 n=n%1000;
 c=n/100;
 n=n%100;
 d=n/10;
 n=n%10;
 sum=a+b+c+d+n;
 cout<<"sum:"<<sum;

getch();

}

Q23.Write a program that inputs basic salary and calculates 35% dearness allowance,25% house rent and then display the gross salary......

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

void main()
  {
  int basic;
  float allow,rent,gross;
  clrscr();
  cout<<"enter basic salary:";
  cin>>basic;
  rent=basic*0.25;
  allow=basic*0.35;
  gross=basic*0.55;
  cout<<"dearness allowance:"<<allow;
  cout<<"\nhouse rent:"<<rent;
  cout<<"\ngross salary:"<<gross;

getch();

}

Q24.Write a program that inputs two times in hh:mm:ss format,adds both times and displays the total time....


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

void main()
{
  int h1,h2,h3,m1,m2,m3,s1,s2,s3;
  clrscr();
  cout<<"enter first time:";
  cin>>h1>>m1>>s1;
  cout<<"enter second time:";
  cin>>h2>>m2>>s2;
  h3=h1+h2;
  m3=m2+m1;
  s3=s2+s1;
  cout<<"sum of two times:"<<h3<<":"<<m3<<":"<<s3;

getch();

}

Q25.Write a progrm that inputs principal amount,rate of interest and total time.It calculates the compound interest and displays it....

#include<iostream.h>
#include<conio.h>
void main()
{

 int am,in,time,i;
 clrscr();
 cout<<"principal amount:";
 cin>>am;
 cout<<"rate of interest:";
 cin>>in;
 cout<<"total time:";
 cin>>time;
 i=(am*in*time)/100;
 cout<<"simple interest:"<<i;

getch();

}

Q26.Write a program that inputs a number and displays its corresponding ASCII code.....

#include<iostream.h>
#include<conio.h>
void main()
{

clrscr();
char charac;
cout<<"enter the character:";
cin>>charac;
int num1=charac;
cout<<"The ASCII code for"<<charac<<"is"<<num1<<endl;

getch();

}


Q27.Write a program that displays the following output:

Number        Square          Cube

1                    1                     1

2                     4                     8

3                     9                     27

4                     16                    64

5                     25                    125


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

void main()

{

 clrscr();
 cout<<"Number\tSquare\tCube\n";
 cout<<"1\t1\t1\n";
 cout<<"2\t4\t8\n";
 cout<<"3\t9\t27\n";
 cout<<"4\t16\t64\n";
 cout<<"5\t25\t125";

getch();

}

Q28.Write a program that inputs marks obtained by a student in five subjects.It then calculates and displays the total marks and percentage.....



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

void main()

{

 int a,b,c,d,e,marks,per,t;
 clrscr();
 cout<<"enter the five subject marks:";
 cin>>a>>b>>c>>d>>e;
 cout<<"total marks";
 cin>>marks;
 t=a+b+c+d+e;
 per=100*(t/marks);
 cout<<"the percentage is:"<<per;

getch();

}













4 comments: