Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

The Output of This Program Is As

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 33

#include<iostream.

h>

#include<conio.h>

Void main ()

Clrscr ();

int a;

float b, c;

cout<<"PROGRAM SHOWING SUM OF TWO NUMBER ";

cout<<"\n enter the value of first integer--->";

cin>>a;

cout<<"\n enter the value of second integer --->";

cin>>b;

c=a+b;

cout<<"\n THE SUM OF TWO INTEGER IS -->"<<c;

getch ();

The output of this program is as:-

PROGRAM SHOWING SUM OF TWO NUMBERS

enter the value of first integer--->56

enter the value of second integer --->56.2


THE SUM OF TWO INTEGER IS -->112.199997

/*Program no 2:- To find the simple interest.*/

#include<iostream.h>

#include<conio.h>

void main ()

clrscr ();

int p,t;

float r,s_i;

cout<<"ENTER THE VALUE OF PRINCIPAL -->";

cin>>p;

cout<<"\nENTER THE VALUE OF RATE --> ";

cin>>r;
cout<<"\nENTER TIME PERIOD ---> ";

cin>>t;

s_i=p*r*t/100;

cout<<"\n THE SIMPLE INTREST IS --> "<<s_i;

getch();

The output of this program is as follows:-

ENTER THE VALUE OF PRINCIPAL -->153

ENTER THE VALUE OF RATE --> 2

ENTER TIME PERIOD ---> 15

THE SIMPLE INTREST IS --> 45.900002

/*Program no.3:- Swaping of two number using third variable.*/

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

void main()

clrscr();

int a,b,c;

cout<<"ENTER FIRST NUMBER--> ";

cin>>a;

cout<<"\n ENTER SECOND NUMBER --->";

cin>>b;

c=a;

a=b;

b=c;

cout<<"\n the swaped value of first intger is"<<a;

cout<<"\n the swaped value of second intger is -->"<<b;

getch();

The out put of the given program is:-

ENTER FIRST NUMBER--> 75

ENTER SECOND NUMBER --->82

the swaped value of first intger is82


the swaped value of second intger is -->75

/*Program no.4:- Swaping of two intger without using third variable.*/

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b;

cout<<"ENTER FIRST NUMBER--> ";

cin>>a;

cout<<"\n ENTER SECOND NUMBER --->";

cin>>b;

a=a+b;

b=a-b;

a=a-b;
cout<<"\n the swaped value of first intger is"<<a;

cout<<"\n the swaped value of second intger is -->"<<b;

getch();

The out put of the given program is as:-

ENTER FIRST NUMBER--> 15

ENTER SECOND NUMBER --->25

the swaped value of first intger is25

the swaped value of second intger is -->15

/*Program no.5- Program to find largest among two number input by user:-*/

#include<iostream.h>

#include<conio.h>

void main()

clrscr();
int a,b;

cout<<"enter the value of a--->";

cin>>a;

cout<<"\n enter the value of b---> ";

cin>>b;

if (a>b)

cout<<"\na is greater than b";

else

cout<<"b is greator than a ";

getch();

The out of this program is:-

enter the value of a--->78

enter the value of b---> 56

a is greater than b
Program no. 6: To calculate the bill of the three items by deducting discount;

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b;

float c,d,p,t;

cout<<"enter the price of first items:- ";

cin>>a;

cout<<"\nenter the price of second items :- ";

cin>>b;

cout<<"\n enter the price of third items :- ";

cin>>c;

t=a+b+c;

if (t>=2000)

d=t*0.5;

else
{ if(t>=1000)

d=t*0.2;

else

{ if (t>=500)

d=t*0.1;

else

d=0;

p=t-d;

cout<<"the total discount is --> "<<d;

cout<<"the total bill after discount is :- "<<p;

getch();

The output of the given program is:-

enter the price of first items:- 458

enter the price of second items :- 56


enter the price of third items :- 25

the total discount is --> 53.900002

the total bill after discount is :- 485.100006

Program no 9:- Using switch case print day names.

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int day;

cout<< "\n Enter a number from 1 to 7 "<<endl;

cin>>day;

switch (day)

case 1:

cout<<"the day is monday ";

break;

case 2:

cout<<"the day is tuesday ";


break;

case 3:

cout<<"the day is wednesday ";

break;

case 4:

cout<<"the day is thusday ";

break ;

case 5:

cout<<"the day is friday ";

break;

case 6:

cout<<"the day is saturday ";

break ;

case 7:

cout<<"the day is sunday ";

break ;

default :

cout<<" invalid choice ";

getch();

The output is as follows;-


Enter a number from 1 to 7

the day is friday


\* Program no 11:- to convert forenheight to Celsius& celcius to forenheight& *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a;

float b,c;

cout<<"Temperature conversion Menu"<"\n";

cout<<"1.Farenheit to celcius"<<"\n";

cout<<"2.celcius to farenheit"<<"\n";

cout<<"enter your choice(1-2):";

cin>>a;

if(a==1)

{{cout<<"\n"<<"enter temperature in farenheit:";

cin>>b;

c=(b-32)/1.8;

cout<<"the temperature in celcius is "<<c<<"\n";

else

{
cout<<"\n"<<"enter temperature in celcius:";

cin>>b;

c=(1.8*b)+32;

cout<<"the temperature in farenheit is"<<c<<'\n";

getch();

\*The output is as follows:-

Temperature conversion Menu1.Farenheit to celcius

2.celcius to farenheit

enter your choice(1-2):1

enter temperature in farenheit:65

the temperature in celcius is 18.333334

Temperature conversion Menu1.Farenheit to celcius

2.celcius to farenheit

enter your choice(1-2):2

enter temperature in celcius:56


the temperature in farenheit is132.800003

\* Program no 18:- to to print ur name five times *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a;

a=0;

for (a=0; a<=5; a++)

{ cout<<"GNDEC "<<endl;}

getch();}

The output is as follows:-

GNDEC

GNDEC

GNDEC

GNDEC

GNDEC
\* Program no 19:- T print int from 1 to 10 *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a;

a=1;

for(a=1; a<=10; a++)

{ cout<<a<<” “;}

getch();

The output isas follows:-

1 2 3 4 5 6 7 8 9 10
\* Program no 22:- To print 1,8,27,64,……1000 *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

a=1;

b=0;

while (b<1000)

{ b=a*a*a;

cout<<b<<",";

a++;

getch();

The output is as follows:-

1,8,27,64,125,216,343,512,729,1000,
\* Program no 23:- To print table of any input no. *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

b=1;

cout<<"enter any number ";

cin>>a;

while (b<=10)

{ c=a*b;

cout<<a<<"*"<<b<<"= "<<c<<endl;

b++; }

getch();

The output is as follows :--

enter any number 19

19*1= 19

19*2= 38

19*3= 57
19*4= 76

19*5= 95

19*6= 114

19*7= 133

19*8= 152

19*9= 171

19*10= 190

\* Program no 24:- To make fabonacci series:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c,n,i,j;

a=0;

b=1;

cout<<"enter the no. of terms of fabonacci series ";

cin>>n;

cout<< a<<endl<<b<<endl;
for(i=1; i<=n-2; i++)

{ c=a+b;

a=b;

b=c;

cout<<c<<endl;}

getch();

The output is as follows:-

enter the no. of terms of fabonacci series 12

13

21

34

55

89
\* Program no 25:- to cal. Factorial of a given number *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

cout<<"enter any number ";

cin>>a;

b=1;

while (a>1)

b=b*a;

a=a-1;

cout<<"factorial is :"<<b;

getch();

The output is as follows:-

enter any number 5


factorial is :120

\* Program no 27:- To reverse a given int *\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

c=0;

cout<<"enter any int :";

cin>>a;

while (a>0)

{ b=a%10;

c=c*10+b;

a=a/10;}

cout<<"the reversed number is : "<<c;

getch();

The output is as follows:-

enter any int :123

the reversed number is : 321


\* program no 29:- to check number is palindrome or not*\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c,d;

c=0;

cout<<"enter any int :";

cin>>a;

d=a;

while (a>0)

{ b=a%10;

c=c*10+b;

a=a/10;}

if (d==c)

{ cout<<"the given number is palandrom " ; }

else {

cout<<" the number is not palandrom ";}

cout<<"the reversed number is : "<<c;


getch();

The output is as follows:-

enter any int :121

the given number is palandrom the reversed number is : 121

\* Program no 31:-To pyramids as shown in the output*\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

a=1;

for(a=1 ; a<=4; a++)

{ for ( b=1; b<=a; b++)

{cout<<a;

cout<<endl;

getch();
}

The output is as follows:-

22

333

4444

\* Program no 36:-To pyramids as shown in the output*\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

a=1;

for(a=1 ; a<=4; a++)

{ for ( b=1; b<=a; b++)

{cout<<"*"

}
cout<<endl;

getch();

The output is as :-

**

***

****

\* Program no 37:-To pyramids as shown in the output*\

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a=5,b,c,d=1;

while (a>=1)

{ b=1;
c=1;

while (b<=a)

{ cout<<" ";

b++;

while(c<=d)

{ cout<<"*";

c++;

cout<<endl;

a--;

d++;

getch();

The output is as follows:-

**

***

****

*****
39) /* Create A Class To Input And Print Record Of Student By Defining Member Function Inside The
Class */

#include<iostream.h>
#include<conio.h>
class student
{
int rno,marks,std;
char name[15];
public:
void read()
{
cout<<"\nEnter name of student:";
cin>>name;
cout<<"\nEnter rno, marks and class:";
cin>>rno>>marks>>std;
}
void display()
{
cout<<"\nName: "<<name;
cout<<"\nRoll No: "<<rno;
cout<<"\nClass: "<<std;
cout<<"\nMarks: "<<marks;
}
};

void main()
{
clrscr();
student k;
k.read();
k.display();
getch();

OUTPUT:

Enter name of student: Anand

Enter rno, marks and class:4493


210

12

Name: Brahmjeet

Roll No: 4483

Class: 12

Marks: 210

40) /* CREATE A CLASS TO CALCULATE FACTORIAL OF AN INTEGER BY DEFINING THE MEMBER


FUNCTION OUTSIDE THE CLASS */

#include<iostream.h>
#include<conio.h>
class factorial
{
int n,fact;
public:
void read();
void process();
void display();
};
void factorial::read()
{
cout<<"\n Enter any number:";
cin>>n;
}
void factorial::process()
{
fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
}
void factorial::display()
{
cout<<"\nFactorial="<<fact;
}
void main()
{
clrscr();
factorial k;
k.read();
k.process();
k.display();
getch();
}

OUTPUT:

Enter any number:5

Factorial=120

43) /* PROGRAM TO IMPLEMENT THE USE OF VIRTUAL FUNCTION */

#include<iostream.h>
#include<conio.h>
class first
{
public:
virtual void yes()
{
cout<<"\nFirst class";
}
};
class second
{
public:
void yes()
{
cout<<"\nSecond class!!!";
};

void main()
{
clrscr();
first *p;
second t;
p=&t;
p->yes();
getch();
}

OUTPUT:

Second class

45) /*Program To Implement Operator Overloading */

#include<iostream.h>
#include<conio.h>
class abhay
{
int a,b;
public:
void read()
{
cout<<"\nEnter any two integers:";
cin>>a>>b;
}
void display()
{
cout<<"\n"<<a<<" "<<b;
}
void operator ++()
{
a++;
b++;
}
};

void main()
{
clrscr();
abhay k;
k.read();
k.display();
k++;
cout<<"\nValue after operator overloading:";
k.display();
getch();}
OUTPUT:

Enter any two integers:45

1000

45 1000

Value after operator overloading:

46 1001

You might also like