You are on page 1of 63

# PROGRAM 1

TITLE:Arithematic operations(+,-,*,/)
LEARNING SCOPE:in this program we use the arithematic operators
CODE:#include<conio.h>
#include<stdio.h>
void main()
{
int x,y,z;
clrscr();
printf("please enter the value of x");
scanf("%d",&x);
printf("please enter the value of y");
scanf("%d",&y);
z=x+y;
printf("addition of x and y is%d",z);
getch();
}

PROGRAM 2

TITLE:Execution of given expression.
a=((x*x)+y-z)*x)
LEARNING SCOPE:in this program we solve the equation

CODE:#include<conio.h>
#include<stdio.h>
void main()
{
int x,y,z,a;
clrscr();
printf("please enter the value of x");
scanf("%d",&x);
printf("please enter the value of y");
scanf("%d",&y);
printf("please enter the value of z");
scanf("%d",&z);
a=((x*x)+y-z)*x)
printf("the value of a is%d",a);

}

getch();

PROGRAM 3
TITLE:type casting
LEARNING SCOPE:in typecasting we change the datatype

CODE:#include<conio.h>
#include<stdio.h>
void main()

scanf("%f".z).is%f". printf("the division of two no. clrscr(). LEARNING SCOPE:by using if else statement we check the given condition . } PROGRAM 4 TITLE:If else program. printf("please enter the value of x").y. scanf("%f".{ float x. printf("please enter the value of y").&y). getch().z.&x). z=x/y.

clrscr(). } else { printf("person is not eligible). } .h> #include<stdio. printf("please enter the value of x"). scanf("%d". } getch().&x). if(x>=18) { printf("person is eligible").CODE:#include<conio.h> void main() { int x.

X=0. CODE:#include<conio. } . y=0.is%d\n".y). getch(). while(x<10) { y=y+x. clrscr().y. x=x+1.h> void main() { int x.PROGRAM 5 TITLE:program to print sum of first 10 natural no.h> #include<stdio. } printf("the sum of first 10 natural no. LEARNING SCOPE:in this program by using while statement we calculate the sum of first 10 natural no.

y. y=0.PROGRAM 6 TITLE:sum of first 10 natural no. using for loop.x++) y=y+1.h> #include<stdio.x<10. CODE:#include<conio. for(x=0. clrscr(). { .h> void main() { int x.

printf("the sum of first 10 natural no. } getch(). } PROGRAM 7 TITLE:EVEN AND ODD FUNTION.y).is %d\n". is even or odd CODE:- . LEARNING SCOPE:it is a simple if else program in which we check whether the given no.

scanf("%d".h> #include<stdio. a=x%2. id odd). } PROGRAM 8 .#include<conio. clrscr(). is even").&x). if(a==0) { printf("given no.h> void main() { int x.a. printf("please enter the value of x"). } getch(). } else { printf("given no.

n.h> void main() { int i. f=1. to calculate factorial\n"). printf("enter the no.h> #include<stdio. clrscr().i--) { f=f*i.i>1. getch(). LEARNING SCOPE:in thid program we use for loop to calculate the factorial CODE:#include<conio. for(i=n. } .f. } printf("the factorial of %d is%d\n".TITLE:FIND FACTORIAL BY USING FOR LOOP. scanf("%d".i).n.&n).

h> void main() { char i.j. .h> #include<stdio.PROGRAM 9 TITLE:TO PRINT ASCII TABLE LEARNING SCOPE:this program will give the ASCII TABLE from 0 to 254 CODE:#include<conio.

h> . } PROGRAM 10 TITLE:PRINT FIBONACC SERIES LEARNING SCOPE:In this program we use while loop. } getch().i.clrscr().i++) { printf("the char of %d no is%c\n".h> #include<stdio.i<254. CODE:#include<conio. for(i=0.i). fibonacc series from 0 to 50 will print in the output.

X2.void main() { int X1. printf("fibonacc series is\n"). if(x2<50) { printf("\n%d". x1=x2. while(x2<50) { x3=x1+x2. ROOT OF GIVEN EQ. x2=x3. LEARNING SCOPE:in this program we use if statement. x1=1. } } getch(). clrscr().X3. x2=1. . } PROGRAM 11 TITLE:FIND SQ.x2).

scanf("%d". . printf("please enter the value of a"). scanf("%d".y).D.h> void main() { int a.CODE:- #include<conio. D=b*b-4a*c.&b). printf("please enter the value of c"). y=-b-sqrtD/2*a. clrscr().h> #include<stdio.b.c.h> #include<math.x. if(D>0) { x=-b+sqrtD/2*a. the roots are \n%d%d". printf("please enter the value of b"). printf("the roots are real and distinct .&a).&c). scanf("%d".y. } if(D==0) { x=-b+sqrtD/2*a.x.

h> . printf("the roots are complex and the roots are %d + i %d\n%d -i %d"x. y=sqrt(-D)/2*a.y). } if(D<0) { x=-b/2*a.y. CODE:#include<conio.x.x).printf("the roots are distinct . the roots are \n %d". } getch(). PROGRAM 12- TITLE:WAP TO CHECK WHETHER THE NO. IS PRIME OR NOT.

is prime"). clrscr(). for(x=2.#include<stdio.&n). } .n. } } if(status==0) { printf("the given no.x++) { { if(n%x==0) status=1.h> void main() { int status.x.x<n. printf("please enter the number"). scanf("%d". } else { printf("the given no. is not prime"). } getch().y.

printf("pRIME NO. } } if(status==0) { .x++) { if(n%x==0) { status=1. scanf("%d".PROGRAM 13- TITLE:WAP TO PRINT PRIME NO. for(x=2. clrscr().n++) { status=0. FROM 1 TO 100 CODE:#include<conio.&n). status=0. FROM 1 TO 100 IS ").x.h> void main() { int status.x<n. for(n=3.n<101.h> #include<stdio.n.

} getch().a. WHEN MIN. . clrscr().y.n. PROGRAM 14 TITLE:WAP TO FIND PRIME NO. RANGE IS GIVEN BY THE USER CODE:#include<conio.").printf("%d is prime no").h> void main() { int status.h> #include<stdio.x. } } else { printf("%d is not prime no. AND MAX.

n<a.printf("please enter the value of x"). printf("please enter the value of y").a<y.&y). for(a=x.a++) { status=0. AND MAX. } PROGRAM 15 TITLE WAP TO PRINT FACTORIAL BETWEEN MIN. scanf("%d". for(n=2. scanf("%d". } } if(status==0) { printf("%d is prime no").&x). RANGE WHICH IS ENTERED BY USER .n++) { if(a%n==0) { status=1. } getch(). status=0.

} printf("the factorial of %lld is lld\n".i>1. clrscr().a.a. } .f. printf("please enter the value of x").a<=y. for(a=x.a++) { f=1.i--) { f=f*i.&y). scanf("%lld".f). } getch().h> void main() { long long int x.CODE:- #include<conio.y. for(i=a. printf("please enter the value of y").&x). scanf("%lld".h> #include<stdio.

scanf("%d".x[i]).i). of array element %d". clrscr().i<10.h> #include<stdio.&x[i]).i<10. for(i=0. is %d\n".i++) { printf("the no.h> void main() { int x[10]. } .i. USING ARRAY.PROGRAM 16 TITLE:PROGRAM TO PRINT THE ENTERED NO. CODE:- #include<conio. } for(i=0.i++) { printf("please enter the no.

PROGRAM 17 TITLE:SUM & AVERAGE OF ARRAY ELEMENTS.j. of array element %d".i.i++) { printf("please enter the no.a. .i). clrscr().h> #include<stdio. CODE:#include<conio.h> void main() { int x[10].} getch(). for(i=0.i<10. float avg.

printf("the average is %f". } j=0. } printf("the sum is %d\n".} scanf("%d".&x[i]).avg).i++) { j=j+x[i]. avg=float9j0/10. CODE:- .j). for(i=0. PROGRAM 17 TITLE:WAP USING ARRAY TO GET MAXIMUM NO. getch().i<10.

for(i=0.&x[i]).max. for(i=0.h> void main() { int x[5]. getch(). of array element %d".i<10.i.max). clrscr().#include<conio.h> #include<stdio.i++) { printf("please enter the no. } } printf("the maximum no. scanf("%d".i).i<5. } .i++) { if(max<x[i]) { max=x[i]. } max=x[0]. is %d\n".

i.min. for(i=0. of array element %d". clrscr().PROGRAM 18 TITLE:WAP USING ARRAY TO GET MINIMUM NO. for(i=0.i++) { .&x[i]).i).i++) { printf("please enter the no.i<10.h> #include<stdio.h> void main() { int x[5]. } min=x[0]. scanf("%d".i<5. CODE:- #include<conio.

is %d\n".h> void main() { int x[5].max).h> #include<stdio.j++) { if(x[i]>x[j]) { x[i]=a.a.i<5.i++) { for(j=i+1. } } printf("the minimum no. . program 19:title:wap a program to arrange the array in ascending order.j. scanf(“%d”.i.j<5. } for (i=0. for (i=0.i++) { printf(“enter the value of array %d”. code:#include<conio.i<5. } getch().i).if(min>x[i]) { min=x[i].&x[i]). clrscr().

j. clrscr().i++) { printf(“the arrays are arranged in ascending order ”.i<2. scanf(“%d”.h> #include<stdio.j++) { printf(“enter the value of array x[%d] [%d]”.i<5. } } } for (i=0.i++) { for(j=0.&x[i][j]). for (i=0.j<2.i.i++) .a.i.j). } getch(). x[j]=j.h> void main() { int x[2][2].x[i]). } } for (i=0. Code:#include<conio. } program 20:title:program to print matrix.i<2.x[i]=x[j].

} .j).x[i][1]).{ for(j=0.i<2.j<2.j++) { printf(“ the value of array is %d”. scanf(“%d”.&x[i][j]).i. } getch().i++) { printf(“ the required matrix is %d %d”.x[i] [0]. } } for (i=0.

.

.a.h> #include<stdio.h> void main() { int x[5]. code:#include<conio.j.program 19:- title:wap a program to arrange the array in ascending order.i.

i++) { printf(“enter the value of array %d”.i<5.x[i]). for (i=0. x[i]=x[j].i).&x[i]). } for (i=0. } } } for (i=0.i++) { for(j=i+1. } getch().i<5.j++) { if(x[i]>x[j]) { x[i]=a.i<5.clrscr().i++) { printf(“the arrays are arranged in ascending order ”. scanf(“%d”. x[j]=j.j<5. } program 20:title:program to print matrix. code:- .

j).j<2.x[i] [0].j++) { printf(“ the value of array is %d”.#include<conio.x[i][1]).&x[i][j]).i<2.i++) printf(“ the required matrix is %d %d”.i.j++) { printf(“enter the value of array x[%d] [%d]”. } getch(). } } for { (i=0.i<2.&x[i][j]). clrscr().i.i++) { for(j=0.h> #include<stdio.h> void main() { int x[2][2]. for (i=0.a.i.i<2.j. scanf(“%d”. } } for (i=0. scanf(“%d”.j). } program 21:- .i++) { for(j=0.j<2.

i<2.j<2. } for (i=0. for (i=0.i<2.TITLE:wap to transpose the given matrix. clrscr().h> #include<stdio.i++) { . } } for (i=0.i. scanf(“%d”.i.h> void main() { int x[3][2].i<2.j++) { printf(“enter the value of array x[%d] [%d]”.j).i++) { for(j=0. } for (i=0.i++) { for(j=0.x[i][0].&x[i][j]).j<2.j.j++) { y[j][i]=x[i][j].y[3][2].i<3.x[i][1]). code:#include<conio.i++) { printf(“ the matrix x[i][j] is %d %d”.

clrscr().h> void main() { unsigned int x[2].h> #include<stdio. printf(“value of p is %u”.printf(“ the matrix y[i][j] is %d%d %d”.*p2. getch().p2-p1). } program 22:- . code:#include<conio.y[i][1]. } program 22:TITLE:wap to print difference of two pointer. } getch(). p1=&x[0]. x[0]=0.y[i][2]). p2=&x[1]. x[1]=9. unsigned int *p1.y[i][0].

scanf(“%d”. p++.i).sum.i<1. } printf(“addition is %u”.i++) { printf(“enter the value of array %d”.h> void main() { int x[10].i. } sum=0. code:#include<conio. int *p. for(i=0. getch().h> #include<stdio. for(i=0.&x[i]).i++) { sum = sum + *p.i<10. } .wap to print the addition of 10 array using pointer.sum). clrscr(). p=&x[0].

h> #include<stdio.program 23:title:program to print factorial using function. scanf(“%d”.f). f=fact(x).f. } .i--) { f=f*i.&x). clrscr(). } void main() { int i.x. printf(“the fact of %d is %d\n”. code:#include<conio. getch(). for(i=x. } return(f). printf(“enter the no\n”).h> int fact(int x) { int f=1.i.i>1.x.

for(x=2. code:#include<conio.program 24:title:WAP TO KNOW THE GIVEN NO.s.x<n.h> int prime(int n) int prime(int n) { int x. } void main() { int x. } } return(s). . printf(“enter the no\n”).y. scanf(“%d”.&n).n. clrscr().x++) { int (n%x==0) { s=1.s=0.h> #include<stdio. IS PRIME OR NOT USING FUNCTION.y.

h> void main() { char n[5].i<5. if(s==0) { printf(“the given no is prime”). } program 25:- title:wap to transpose the given matrix.i<5.i++) { printf(“\n enter the array char”). for (i=0. } for (i=0.h> #include<stdio. clrscr(). n[i]=getche().r[5].i++) { . } else { printf(“the given no. code:#include<conio. } getch(). is not prime).s=prime(n).

} for (i=0. } getch().h> . is not palindrome”). break.h> #include<string. code:#include<conio.r[4-i]=n[i]. } program 26:title:wap to print the info of book using structure.h> #include<stdio.i++) { if(r[i]!=n[i]) { j=1. } } if(j==0) { printf(“ the no. } else { printf(“ the no.i<5. is palindrome”).

b[i].i++) { printf(“enter the name of book %d=i”). int pages. } for(i=0.&b[i]. clrscr().pages). printf(“ pages=%s”. }.i<3. printf(“enter the name of pages %d=i”).struct book { char name[20]. } program 27:title:wap to create class and object.b[i]. } getch().name). void main() { book b[3]. for(i=0.i++) { printf(“book = %s\n”.i<3. . scanf(“%s”.name).&b[i]. scanf(“%s”. int i.name).

void main() { book b[3] int i.i<3.i++) { cout<<”\nbook=”<<b[i]. cin>>b[i]. cout<<”enter the name of pages”<<i.h> class book { public: int pages. }.h> #include<stdio. clrscr().name. for(i=0. } getch().pages. cin>>b[i]. char name[10]. } for(i=0. cout<<”\npages=”<<b[i].i++) { cout<<”enter the name of book”<<i.pages.i<3.code:#include<conio.name. } .

} for(i=0.i<3.program 28:title:wap to print the name & price of car using class and object. cin>>c[i]. }.h> #include<iostream. . cout<<"enter the price of car"<<i.name.i++) { cout<<"enter the name of car"<<i. int price.name. void main() { car c[3].i++) { cout<<"\n name="<<c[i].i<3.h> class car { public: char name[10]. for(i=0. int i.price. #include<conio. cin>>c[i].

} getch(). #include<conio. int price.h> #include<iostream.price. . public: void setvalue(int price_e. price=price_e. } char get_name() { return(name).h> class car { private: char name. } PROGRAM 29:TITLE:USE OF PRIVATE.char name_e) { name=name_e.cout<<"\n price="<<c[i].

int i.p.i++) { cout<<"enter the name of car"<<i.p). char n.setvalue(n. cout<<"enter the price of car"<<i. c[i].get_price().} int get_price() { return(price).i<3.i<3. } getch(). cout<<"\n price="<<c[i].get_name(). cin>>n. void main() { car c[3].i++) { cout<<"\n name="<<c[i]. } for(i=0. } }. cin>>p. for(i=0. } .

public: void setvalue(int price_e. int price. char get_name(). price=price_e.PROGRAM 30:TITLE:DECLARATION OF MEMBER FUNCTION OUTSID EHTE BODY. } char car::get_name() { return(name). void car::setvalue(int price_e. }. CODE:#include<conio.char name_e).h> class car { private: char name. int get_price().h> #include<iostream.char name_e) { name=name_e. } int car::get_price() .

{ } return(price). cout<<"\n price="<<c[i]. } .get_name(). char n.p. } for(i=0. int i.p). c[i].setvalue(n.get_price().i<3.i++) { cout<<"enter the name of car"<<i.i<3. cin>>p. void main() { car c[3].i++) { cout<<"\n name="<<c[i]. for(i=0. cin>>n. } getch(). cout<<"enter the price of car"<<i.

PROGRAM 31:WAP OF CONSTRUCTER.int price_e). int price. price=100. int get_price(). char get_name().int price1) { name=name1.h> #include<iostream. . #include<conio. } car(char name1. car() { name='a'. } car(char name2) { name=name2.h> class car { private: char name. price=price1. public: void setvalue(char name_e.

price=2000;
}
car(int price2)
{
price=price2;
name='e';
}
};
void car::setvalue(char name_e,int price_e)
{
name=name_e;
price=price_e;
}
char car::get_name()
{
return(name);
}
int car::get_price()
{
return(price);
}
void main()
{
car c[3];
car c1('c',1000);
int i,p;
char n;

clrscr();
for(i=0;i<3;i++)
{
cout<<"enter the name of car"<<i;
cin>>n;
cout<<"enter the price of car"<<i;
cin>>p;
c[i].setvalue(n,p);
}
for(i=0;i<3;i++)
{
cout<<"\n name="<<c[i].get_name();
cout<<"\n price="<<c[i].get_price();
}
cout<<"\n name="<<c1.get_name();
cout<<"\n price="<<c1.get_price();
getch();
}

PROGRAM

32:-

TITLE:DESTRUCTOR.
#include<conio.h>
#include<iostream.h>
class ball
{
private:
char color;
int price;
public:
void setvalue(char color_r,int price_e);
char get_color();
int get_price();
ball()
{
color='a';
price=100;
}
ball(char color1,int price1)
{
color=color1;
price=price1;
}
ball(char color2)
{
color=color2;
price=2000;
}
car(int price2)

int price_e) { color=color_r. } void main() { ball b[3]. } }.{ color='e'. ball b1('c'. } ~ball() { cout<<"I am destructor".1000). price=price2. } int ball::get_price() { return(price). price=price_e. } char ball::get_color() { return(color). . void ball::setvalue(char color_r.

i<3. cin>>c. cout<<"enter the price of ball"<<i.setvalue(c.get_price(). b[i].p).i++) { cout<<"enter the color of ball"<<i. cin>>p. cout<<"\n price="<<b[i].get_price().int i.i++) { cout<<"\n color="<<b[i]. } for(i=0.p. char c. clrscr().i<3. } cout<<"\n color="<<b1.get_color(). } PROGRAM 32:- . cout<<"\n price="<<b1. for(i=0.get_color(). getch().

TITLE:DECLARATION OF MEMBER FUNCTION INSIDE THE BODY. int price. } char ball::get_color() { return(color). } int ball::get_price() { . price=price_e.int price_e) { color=color_r. public: void ball::setvalue(char color_r.h> class ball { private: char color.h> #include<iostream. #include<conio.

price=2000. price=100. //char get_color(). } ~ball() { . price=price2.return(price). } car(int price2) { color='e'. ball() { color='a'.int price_e). } ball(char color1.int price1) { color=color1. } //void setvalue(char color_r. price=price1. // int get_price(). } ball(char color2) { color=color2.

3000). }.p). for(i=0.i<3. ball b1('B'. ball b2('C'.2000). } for(i=0.i<3.get_color(). } void main() { ball b[3]. cout<<"\n price="<<b[i]. clrscr(). cin>>c. b[i].i++) { cout<<"enter the color of ball"<<i. } . cin>>p.i++) { cout<<"\n color="<<b[i]. cout<<"enter the price of ball"<<i.setvalue(c.get_price().1000). int i.cout<<"I am destructor". char c.p. ball b0('A'.

get_color().h> class car . cout<<"\n price1="<<b1. cout<<"\n price2="<<b2. cout<<"\n color2="<<b2.get_color(). } PROGRAM 33:TITLE:INHERITENCE AND FUNCTION OVERLOADING. CODE:#include<conio. cout<<"\n price0="<<b0.get_color().get_price(). cout<<"\n color1="<<b1.get_price().cout<<"\n color0="<<b0.get_price().h> #include<iostream. getch().

void display() { .{ . int price. void display() { cout<<endl<<"display function of maruti" . class maruti:public car { public: int seats. } }. class tata:public maruti { public: int rpm. void display() { cout<<endl<<"display function of car" } }. char colorcode. public: char modelcode.

cout<<endl<<"colorcode=". } }. tata t. . cout<<endl<<"price="<<c.display().cout<<endl<<"display function of tata" . cout<<endl<<"seats=". void main() { clrscr(). c. cout<<endl<<"rpm="<<t. cout<<endl<<"modelcode="<<c.seats. cin>>t. cout<<endl<<"rpm=". cin>>c.modelcode.colorcode. car c.price. cout<<endl<<"price=". cout<<endl<<"colorcode="<<c.rpm.seats.rpm. cin>>c. cin>>c.modelcode.price. cout<<endl<<"seats="<<m. cin>>m. cout<<endl<<"modelcode=". maruti m.colorcode.

} getch().h> #include<iostream.display(). CODE:#include<conio. int price.m. virtual void display() { cout<<endl<<"display function of ball" .display(). PROGRAM 34:TITLE:VIRTUAL FUNCTION. t.h> class ball { public: char colorcode. .

void display() { cout<<endl<<"display function of material_type" . //void display() //{ // cout<<endl<<"display function of area" . . class area:public ball { public: int radius. } }. area a. void main() { clrscr(). class material_type:public area { public: char material. //} }. ball b.} }.

cout<<endl<<"colorcode=". t. cin>>t.display(). cout<<endl<<"material=". //cout<<endl<<"radius="<<a.price. //cin>>a.display().colorcode.price.material. cout<<endl<<"colorcode="<<b.material.material_type t. b. //cout<<b. cin>>b. getch(). a.radius. cout<<endl<<"material="<<t.radius. } PROGRAM 35 .colorcode. cout<<endl<<"price=". cin>>b.display().display(). cout<<endl<<"price="<<b. cout<<endl<<"radius=".

cin>>i.h> #include<iostream. if(i==str) { cout<<"correct password"<<endl. CODE:#include<conio. cout<<"enter the password=".TXT"). . int str = 12345. outfile.h> void main() { ofstream outfile ("PASSWORD. clrscr().h> #include<fstream. } else { cout<<"incorrect password"<<endl. outfile<<str<<endl.TITLE:FILE HANDLING. int i.close().

} if(i%str==0) { ifstream infile("PASSWORD. infile>>str. } getch(). } .TXT"). cout<<"correct password is"<<str<<endl.