Wednesday, May 30, 2018

c++ SET 1 FOR ENGINEERING STUDENTS

 SET 1
1.    Write  a program to add two numbers given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
c=a+b;
cout<<"Sum "<<c<<"\n";
getch();
}

2. Write a program to calculate the area of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
cout<<"Area of Rectangle "<<a<<"\n";
getch();
}

3.Write a program to calculate the area of a Circle.
#include<iostream.h>
#include<conio.h>
void main()
{
float r,ar;
clrscr();
cout<<”enter radius”;
cin>>r;
ar=22/7*r*r;
cout<<”area of circle”<<ar<<endl;
getch();
}

4.Write a program to calculate the area and perimeter of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,p;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
p=2*(l+b);
cout<<"Area of Rectangle "<<a<<"\n";
cout<<"Perimeter of Rectangle "<<p<<"\n";
getch();
}

5.Write a program to find the total and average of a student who has appeared for three subjects.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
clrscr();
cout<<"Enter Marks Of A";
cin>>a;
cout<<"Enter Marks of B";
cin>>b;
cout<<”Enter Marks of C;
cin>>c;
d=a+b+c;
cout<<”Total Marks of Three Subjects<<d;
e=(a+b+c)/2;
cout<<”Average Marks Of Three Subjects”<<e;
getch();
}

6. Write a program to calculate the total resistance of a circuit if the two resistors are    connected in series and connected in parallel.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float  r1,r2,a,b;
cout<<”Enter Resistor 1”;
cin>>r1;
cout<<”Enter Resistor 2”;
cin>>r2;
a=r1+r2;
cout<<”Total Resistance When Resistors Are Connected In Series”<<a<<endl;
b=(r1*r2)/(r1+r2);
cout<<”Total Resistance When Resistors Are Connected In Parallel”<<b<<endl;
getch();
}

7. Write a program to find the third angle of a triangle if the two angles is given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
cout<<”enter angle 1”;
cin>>a;
cout<<”enter angle 2”;
cin>>b;
c=a+b;
d=180-c;
cout<<”Third Angle”<<d<<endl;
getch();
}

8.Write a program to convert meter to centimeter.
#include<iostream.h>
#include<conio.h>
void main()
{
float m,cm;
clrscr();
cout<<”enter meter”;
cin>>m;
cm=m*100;
cout<<”centimeter=”<<cm<<endl;
getch();
}

9. Write a program to convert hour into minutes and seconds.
#include<iostream.h>
#include<conio.h>
void main()
{
int h,m,s;
clrscr();
cout<<”enter hours”;
cin>>h;
m=h*60;
cout<<”Hours In Minutes”<<m<<endl;
s=h*60*60;
cout<<”Hours In Seconds”<<s<<endl;
getch();
}

10. Write a program to convert kilometer to yards.
#include<iostream.h>
#include<conio.h>
void main()
{
float  km,y;
cout<<”enter kilometer”;
cin>>km;
y=1094*km;
cout<<”yards=”<<y<<endl;
getch();
}

11.  Write a program to convert centigrade temperature to Fahrenheit temperature
#include<iostream.h>
     #include<conio.h>
     void main()
     {
     int c.f;
     clrscr();
     cout<<"enter temperature in centigrade";
     cin>>c;
     f=(9*c)/5+32;
     cout<<"temperature in farenhiet";
     getch();
     }  
12.    Write a program to convert yards to meter and kilometer
 #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int y.km.m;
     clrscr();
     cout<<"enter length in yard";
     cin>>y;
     km=y*0.0009144
     cout<<"length in kilomtre"<<km;
     m=y*0.9144
     cout<<"length in metre"<<m;
     getch();
     }
17.    Write a program to convert seconds into Hour, Minute, and Seconds
  #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int s,m,hr,rs;
     clrscr();
     cout<<"enter seconds";
     cin>>s;
     m=s/60
     rs=s%60;
     hr=s/3600
     rs=s%3600;
     cout<<"time in minutes"<<m;
     cout<<"time in hour"<<hr;
     cout<<"time in seconds"<<rs;
     getch();
     }
18.    Write a program to convert centimeter to meter and Centimeter
 #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int cm,m,rcm;
     clrscr();
     cout<<"enter length in centimeter";
     cin>>cm;
     m=cm/100
     rcm=cm%100;
     cout<<"length in meter"<<m;
     cout<<"length in centimeter"<<rcm;
     getch();
     }

20.    Write a program, A person goes to Bank to withdraw certain amount of money. If the bank gives the change in Rs 5 and Re 1 find out how many 5 Rs note and how many 1 Re note the person receives
     #include<iostream.h>
     #include<conio.h>
     #include<math.h>
     void main()
     {
     int amt,hun,fif,ten,two,one;
     clrscr();
     cout<<"enter amount to be withdrawn";
     cin>>amt;
     hun=amt/100;
     amt=amt%100;
     fif=amt/50;
     amt=amt%50;
     ten=amt/10;
     amt=amt%10;
     two=amt/2;
     amt=amt%2;
     one=amt/1;
     amt=amt%1;
     cout<<"100*"<<hun<<endl;
     cout<<"50*"<<fif<<endl;
     cout<<"10*"<<ten<<endl;
     cout<<"2*"<<two<<endl;
     cout<<"1*"<<one<<endl;
     getch();
     }