Research Area

Ashutosh Dubey

Saturday, April 3, 2010

Basic Programs in C++

1. Write a program to print a welcome msg ": welcome in c++"?


#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"welcome in c++";

getch();

}

2. Write a program to enter three numbers to print the sum, multiplication, division?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,sum,div,pdt;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter two no.";

cin>>a>>b;

cout<<"sum"<<a+b;

cout<<"\ndiv"<<a/b;

cout<<"\nmul

"<<a*b;

getch();

}

3. Write a program to swap two numbers using third variable?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a &b";

cin>>a>>b;

c=a;

a=b;

b=c;

cout<<a<<"\n"<<b;

getch();

}

4. Write a program to swap two numbers without using third variable?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a &b";

cin>>a>>b;

a=a+b;

b=a-b;

a=a-b;

cout<<a<<"\n"<<b;

getch();

}



5. Write a program to enter the radius of the circle and find the area of the circle?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float r,area;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter radius";

cin>>r;

area=3.142*r*r;

cout<<"area"<<area;

getch();

}

6. Write a program enters the three sides of triangles and find area of triangle by hero’s formula?



#include<iostream.H>

#include<conio.h>

#include<math.h>

void main()

{

clrscr();

float a,b,c,s,t;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three sides of the triangle";

cin>>a>>b>>c;

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

cout<<s;

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

cout<<t;

getch();

}

7. Write a program for beggars’ associations where we have four cups first cup accept 50 rps 2nd cup accept 100 rs 3rd cup accept 500rps and 4rth cups accept 1000 rs enter the amount whatever the user wants print total number of rupees and the total amount?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int A,B,C,D,TOTAL,MONEY;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"ENTER THE NOTES IN A";

cin>>A;

cout<<"ENTER THE NOTES IN B";

cin>>B;

cout<<"ENTER THE NOTES IN C";

cin>>C;

cout<<"ENTER THE NOTES IN D";

cin>>D;

TOTAL=A+B+C+D;

MONEY=(A*50)+(B*100)+(C*500)+(D*1000);

cout<<"TOTAL NOTES IN CUPS ARE ="<<TOTAL<<endl;

cout<<"TOTAL MONEY IN CUPS ="<<MONEY;

getch();

}



8. Write a program to find the simple interest where p, r, t is given by the user?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int p,r,t,si;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the principle rate and time"<<endl;

cin>>p>>r>>t;

si=(p*r*t)/100;

cout<<"simple interest="<<si;

getch();

}



9. Write a program find the area of a triangle where base and height is input by the user?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int h,b,area;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the height and base"<<endl;

cin>>h>>b;

area=(h*b)/2 ;

cout<<area;

getch();

}

10. Write a program to enter three digit numbers and print the sum of those digits?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d,sum;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three digit number"<<endl;

cin>>a;

b=a/100;

c=(a%100)/10;

d=a%10;

sum=b+c+d;

cout<<sum;

getch();

}

11. Write a program to enter the three digit number and print its reverse order?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d,rev;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three digit number"<<endl;

cin>>a;

b=a/100;

c=(a%100)/10;

d=a%10;

rev=d*100+c*10+b;

cout<<rev;

getch();

}

12. Write a program to enter the three digit number and find the sum of first and last digit ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a three digit number"<<endl;

cin>>a;

b=a/100;

c=a%10;

d=c+b;

cout<<d;

getch();

}





Submitted By

Gaurav Agarwal

CSE Iv Sem.

TITR Bhopal

No comments: