Vous êtes sur la page 1sur 39

PROGRAM NO. 1: WAP for addition of 2 nos.

#include<iostream.h> #include<conio.h> void main() {int a,b,c; cout<<"enter first no."; cin>>a; cout<<"enter second no."; cin>>b; c=a+b; cout<<"the result is"<<c; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.2: WAP for Subtraction of two nos.

#include<iostream.h> #include<conio.h> void main() {int a,b,c; cout<<"enter first no."; cin>>a; cout<<"enter second no."; cin>>b; c=a-b; cout<<"the result is"<<c; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.3: WAP for Multiplication of two nos.

#include<iostream.h> #include<conio.h> void main() {int a,b,c; cout<<"enter first no."; cin>>a; cout<<"enter second no."; cin>>b; c=a*b; cout<<"the result is"<<c; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.4: WAP for Division of two nos.

#include<iostream.h> #include<conio.h> void main() {int a,b,c; cout<<"enter first no."; cin>>a; cout<<"enter second no."; cin>>b; c=a/b; cout<<"the result is"<<c; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.5: WAP to perform arithmetic problems

#include<iostream.h> #include<conio.h> void main() {int a,b,c,d,e,f; cout<<"enter first no."; cin>>a; cout<<"enter second no."; cin>>b; c=a+b; d=a-b; e=a*b; f=a/b; cout<<"the result of addition is"<<c; cout<<"the result of subtraction is"<<d; cout<<"the result of multiplication is"<<e; cout<<"the result of division is"<<f; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.6: WAP to calculate circumference of circle

#include<iostream.h> #include<conio.h> void main() {int r,a; cout<<"enter radius of circle "; cin>>r; a=2*3.14*r*r; cout<<"circumference of circle is"<<a; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.7: WAP to calculate area of square


#include<iostream.h> #include<conio.h> void main() {int s,a; cout<<"enter side of square "; cin>>s; a=s*s; cout<<"area of square is"<<a; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.8: WAP to calculate area of rectangle

#include<iostream.h> #include<conio.h> void main() {int l,b,a; cout<<"enter length of rectangle "; cin>>l; cout<<"enter breadth of rectangle"; cin>>b; a=l*b; cout<<"area of rectangle is"<<a; getch(); }

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.9: WAP to calculate the value of s

#include<iostream.h> #include<conio.h> void main() { int s,t,a,u; cout<<"enter the value of s "; cin>>s; cout<<"enter the value of t"; cin>>t; cout<<"enter the value of a"; cin>>a; cout<<"enter the value of u"; cin>>u; s=u*t+1/2*a*t*t; cout<<"result is"<<s; getch();
}

OUTPUT:

Shagun Gupta 90520414178

PROGRAM NO.10: WAP to calculate average of 5 subjects

#include<iostream.h> #include<conio.h> void main() {int a,b,c,d,e,f; cout<<"marks of maths is "; cin>>a; cout<<"marks of english is"; cin>>b; cout<<"marks of science is"; cin>>c; cout<<"marks of hindi is "; cin>>d; cout<<"marks of computer is"; cin>>e; f=a+b+c+d+e/5; cout<<"average marks of 5 subject is"<<f; getch(); }

OUTPUT:

10

Shagun Gupta 90520414178

Program no.11: WAP to display first 10 nos.

#include<iostream.h> #include<conio.h> void main() {clrscr(); int i; for(i=0;i<11;i++) cout<<i<<"\n"; getch(); }

OUTPUT:

11

Shagun Gupta 90520414178

PROGRAM NO 12: WAP for finding whether an alphabet in vowel or not.


#include<iostream.h> #include<conio.h> void main() {clrscr(); char b; cout<<"enter the char"; cin>>b; if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u') cout<<"vowels"; else cout<<"consonants"; getch(); }

OUTPUT:

12

Shagun Gupta 90520414178

PROGRAM NO.13: WAP to print your roll no.& roll no.


#include<iostream.h> #include<conio.h> void main() {clrscr(); char a[20]; int r; cout<<"enter your name";
13 Shagun Gupta 90520414178

cin>>a; cout<<"enter your roll no."; cin>>r; cout<<"your name is "<<a<<"\n"; cout<<"your name is"<<r; getch(); }

OUTPUT:

PROGRAM NO 14: WAP for finding whether the no. is even or odd.
#include<iostream.h> #include<conio.h> void main() {clrscr(); int num;
14 Shagun Gupta 90520414178

cout<<"enter no."; cin>>num; if (num % 2==0) cout<<"no. is even"; else cout<<"no. is odd"; getch(); } OUTPUT: for even no.

For odd no.:

PROGRAM NO.15: WAP to swap two nos.


#include<iostream.h> #include<conio.h> void main()
15 Shagun Gupta 90520414178

{clrscr(); int a,b,c; cout<<"enter values"; cin>>a>>b; cout<<"before swapping values are"; cout<<"a is "<<a; cout<<"b is"<<b; c=a; a=b; b=c; cout<<"after swapping values are"; cout<<"a is "<<a; cout<<"b is"<<b; getch(); }

OUTPUT:

PROGRAM NO.16: WAP to find greater of two nos.


#include<iostream.h> #include<conio.h> void main()
16 Shagun Gupta 90520414178

{clrscr(); int a,b; cout<<"enter two nos."; cin>>a>>b; if (a>b) cout<<"A is greater"; else cout <<"B is greater"; getch(); }

OUTPUT:

PROGRAM NO. 17: WAP to find greater among 3 nos.


#include<iostream.h> #include<conio.h>
17 Shagun Gupta 90520414178

void main() { clrscr(); int a,b,c; cout<<"enter three nos."; cin>>a>>b>>c; if (a>b && a>c) cout<<"A is greater"; else if (b>a && b>c) cout<<"B is greater"; else cout<<" C is greater"; getch(); }

OUTPUT:

PROGRAM NO. 18: WAP to display nos. till you enter zero

18

Shagun Gupta 90520414178

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i; do { cout<<"enter no."; cin>>i; cout<<"you entered"<<i; } while (i!=0); }

OUTPUT:

PROGRAM NO.19: WAP for addition of two nos. using function


#include<iostream.h>
19 Shagun Gupta 90520414178

#include<conio.h> void main() { clrscr(); int a,b,c; cout<<"enter a,b"; cin>>a>>b; int sum(int,int); c= sum(a,b); cout<<"result is"<<c; getch(); } int sum (int x, int y) {int z; z= x+y; return (z); getch(); }

OUTPUT:

PROGRAM NO. 20: WAP to print days of the week using switch case
#include<iostream.h> #include<conio.h> void main() { 20 Shagun Gupta 90520414178

clrscr; int n; cout<<"enter the no. between 1-7"; cin>>n; switch (n) { case 1:cout<<"monday"; break; case 2:cout<<"tuesday"; break; case 3:cout<<"wednesday"; break; case 4:cout<<"thursday"; break; case 5:cout<<"friday"; break; case 6:cout<<"saturday"; break; case 7:cout<<"sunday"; break; default: cout<<"wrong choice"; } getch();}

OUTPUT:

21

Shagun Gupta 90520414178

PROGRAM NO. 21: WAP to calculate the factorial of a no. using recursion
#include<iostream.h> #include<conio.h> void main() { clrscr(); int fact = 1,i,n; cout<<"enter the no."; cin>>n; for (i=1;i<=n;i++) fact=fact*i; cout<<"factorial is"<<fact; getch(); }

OUTPUT:

22

Shagun Gupta 90520414178

PROGRAM NO.22: WAP to enter the element into 1-D array


#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,a[100]; cout<<"enter no. of elements"; cin>>n; for(i=0;i<n;i++) cin>>a[i]; for (i=0;i<n;i++) cout<<a[i]; getch(); }
23 Shagun Gupta 90520414178

OUTPUT:

PROGRAM NO. 23: WAP to calculate largest element in 1-D array


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[100]; int i,n,x; cout<<"how many elements you want to enter"; cin>>n; for (i=0;i<n;i++) cin>>a[i]; for (i=0;i<n;i++) cout<<a[i]; x=a[i];
24 Shagun Gupta 90520414178

cout<<"largest element in array is"<<x; getch(); }

OUTPUT:

PROGRAM NO.24: WAP to concaniate 2 strings


#include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char a[10]="hello"; char b[10]="its me"; strcat (a,b); cout<<a; getch(); }

OUTPUT:
25 Shagun Gupta 90520414178

PROGRAM NO.25: WAP to compare 2 strings


#include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char a[10]="bye"; char b[10]="bye"; int I=strcmp (a,b); cout<<I; getch(); }
26 Shagun Gupta 90520414178

OUTPUT:

PROGRAM NO.26: WAP to copy string 2 in string 1


#include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char a[10]; char b[10]="hello"; strcpy (a,b); cout<<a; getch(); }

OUTPUT:
27 Shagun Gupta 90520414178

Program No.27 WAP to calculate the length of string.


#include<conio.h> #include<iostream.h> #include<string.h> void main() { clrscr(); char a[20]="hello"; int i=strlen(a); cout<<"length of string"<<i; getch();

} Output:

28

Shagun Gupta 90520414178

Program no.28 WAP for function with no argument and no return value.

#include<conio.h> #include<iostream.h> void main() { clrscr(); void add(); add(); getch(); } void add()
29 Shagun Gupta 90520414178

{int a=2,b=3,c; c=a+b; cout<<c; } Output:

Program No.29 WAP to swap two numbers using call by value.


#include<iostream.h> #include<conio.h> void swap(int,int); void main() { clrscr(); int a,b; cout<<"enter the value of a and b"<<"\n"; cin>>a>>b; swap(a,b); cout<<"value after swapping"<<"\n"; cout<<"value of a and b"<<"\n"; cout<<a<<b; getch(); } void swap(int x,int y) {int temp; temp=x; x=y; 30 Shagun Gupta 90520414178

y=temp; cout<<"swapped are"; cout<<x<<y; } Output:

Program No.30 WAP to swap two numbers using call by reference.


#include<iostream.h> #include<conio.h> void swap(int&,int&); int main() { clrscr(); int a,b; cout<<"enter the value of a and b"; cin>>a>>b; swap(a,b); cout<<"value of a and b"; cout<<a<<b; return 0; } void swap(int &x,int &y) {int temp; temp=x; 31 Shagun Gupta 90520414178

x=y; y=temp; cout<<"swapped are"; cout<<x<<y; getch(); }

Output:

Program No.31 WAP for factorial of two numbers using recursion.


#include<iostream.h> #include<conio.h> void main() { clrscr(); long l; long fact(long); cout<<"enter number"; cin>>l; long fact(long); cout<<"factorial is"<<fact(l); getch(); } long fact(long a) {
32 Shagun Gupta 90520414178

if(a>1) return(a*fact(a-1)); else return(1); }

OUTPUT:

Program No.32 WAP for go to statement.


#include<iostream.h> #include<conio.h> void main() { clrscr(); int n=10; loop: cout<<n; n--; if (n>0)goto loop; getch(); }

OUTPUT:
33 Shagun Gupta 90520414178

Program No.33 WAP to enter student information using structure.


#include<iostream.h> #include<conio.h> struct student {char name[30],trade[30]; int r; }; void main() {

clrscr(); struct student s1,s2,s3; cout<<"enter the record of first student"<<"\n"; cout<<"enter name"<<"\n"; cin>>s1.name; cout<<"enter roll no."<<"\n"; cin>>s1.r; cout<<"enter trade"<<"\n"; cin>>s1.trade; cout<<"record of first student is"<<"\n"; cout<<"name is"<<s1.name<<"\n";
34 Shagun Gupta 90520414178

cout<<"roll no. is"<<s1.r<<"\n"; cout<<"trade is"<<s1.trade<<"\n"; cout<<"enter the record of second student"<<"\n"; cout<<"enter name"<<"\n"; cin>>s2.name; cout<<"enter roll no."<<"\n"; cin>>s2.r; cout<<"enter trade"<<"\n"; cin>>s3.trade; cout<<"record of second student is"<<"\n"; cout<<"name is"<<s2.name<<"\n"; cout<<"roll no. is"<<s2.r<<"\n"; cout<<"trade is"<<s2.trade<<"\n"; getch(); }

OUTPUT:

35

Shagun Gupta 90520414178

Program No.34 WAP to enter the student information using array with structure.
#include<iostream.h> #include<conio.h> struct student {char name[30],trade[30]; int r; }; void main() { clrscr(); struct student s[200]; int n,i; cout<<"enter the no. of students"; cin>>n; for(i=1;i<+n;i++) {cout<<"enter the information of"<<i<<"student"<<"\n"; cout<<"enter name"<<"\n"; cin>>s[i].name; cout<<"enter roll no."<<"\n"; cin>>s[i].r; cout<<"enter trade"<<"\n"; cin>>s[i].trade;} for(i=1;i<=n;i++) 36 Shagun Gupta 90520414178

{cout<<"record of "<<i<<"student is"<<"\n"; cout<<"name is"<<s[i].name<<"\n"; cout<<"roll no. is"<<s[i].r<<"\n"; cout<<"trade is"<<s[i].trade<<"\n"; } getch(); }

OUTPUT:

Program No.35 WAP to enter the student information using union.


#include<iostream.h> #include<conio.h> union student { //char a; int r; float m; }; void main() { union student s1; cout<<"enter the information of the student"; cin>>s1.r; cout<<"s1.r"<<"\n"; cout<<sizeof(s1); getch(); }

OUTPUT:

37

Shagun Gupta 90520414178

Program No.36 WAP for member function inside the class definition.
#include<iostream.h> #include<conio.h> class student { private: int r; char name[30]; public: void enter() { cout<<"enter the name of student"; cin>>name; cout<<"enter roll number of student"; cin>>r; } void display() { cout<<"name of student is"<<name<<"\n"; cout<<"roll number of student is"<<r;
38 Shagun Gupta 90520414178

} }; void main() { clrscr(); class student s1; s1.enter(); s1.display(); getch(); }

OUTPUT:

39

Shagun Gupta 90520414178

Vous aimerez peut-être aussi