You are on page 1of 35

Wap to find the sum of two numbers using function.

#include<conio.h> #include<stdio.h> #include<iostream.h> #include<math.h> int sum(int x,int y) {int s; s=x+y; return s; } void main() { clrscr(); int a,b,k; cout<<"Enter 2 numbers:\n"; cin>>a>>b; k=sum(a,b); cout<<"\nSum of 2 numbers is:\n"<<k; getch(); }

Wap to find simple interest and compound interest.


#include<conio.h> #include<stdio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); float p,r,t,ci,si,i; int a; cout<<"Enter Principle amount:\n"; cin>>p; cout<<"\nEnter Rate of interest:\n"; cin>>r; cout<<"\nEnter time in years:\n"; cin>>t; cout<<"\n\n1.Compound interest\n"; cout<<"2.Simple interst\n"; cout<<"Choose your option:\n"; cin>>a; switch(a) { case 1:float f=1; for(i=0;i<t;i++) {f=f*(1+(r/100)); } ci=p*f; cout<<"\nCompound Interest is:\n"<<ci; break; case 2:si=(p*r*t)/100; cout<<"Simple Interest is:\n"<<si; break; } getch(); }

Wap to demonstrate the working of following loop : While, Do While, For, IfElse, Switch.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int f=1,s=0,a,x,i=1; char ch; do { cout<<"Enter a number:\n"; cin>>x; cout<<"\n1.Factorial\n"; cout<<"2.+ve or -ve or 0\n"; cout<<"3.Sum upto\n"; cout<<"Choose your option\n"; cin>>a;

switch(a) { case 1:while(i<x) { f=f*i; i++; } cout<<"\nFactorial"<<f<<"\n"; break; case 2:if(x<0) cout<<"\n-ve\n"; else if(x>0) cout<<"\n+ve\n"; else cout<<"0"; break; case 3:for(i=0;i<=x;i++) { s=s+i; } cout<<"\nSum:\n"<<s<<"\n"; break; } cout<<"\nDo you wish to continue (y/n)?\n"; cin>>ch;

} while(ch=='y' || ch=='n'); getch(); }

WAP to find greatest of three numbers.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int a,b,c,s; cout<<"Enter 3 numbers:\n"; cin>>a>>b>>c; if(a>b) { if(a>c) s=a; else s=c; } else s=b; cout<<"\nGreatest number:\n"<<s;

getch(); }

WAP to check whether a number is even or odd.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int x; cout<<"Enter a no:\n"; cin>>x; if(x%2==0) cout<<"Even no\n"; else cout<<"Odd\n"; getch(); }

WAP to check whether a year is leap year or not.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int x; cout<<"Enter year:\n"; cin>>x; if(x%4==0) cout<<"Leap year\n"; else cout<<"Not a leap year\n"; getch(); }

WAP to add and subtract two matrices.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int a[10][10],b[10][10],c[10][10],m,n,i,j; cout<<"Enter size of matrix m*n:\n"; cin>>m>>n; cout<<"\nEnter elements of matrix A:\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; cout<<"\n"; } } cout<<"\nEnter elements of matrix B:\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) {

cin>>b[i][j]; cout<<"\n"; } } cout<<"\nArray A\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cout<<a[i][j]; cout<<" "; } cout<<"\n"; } cout<<"\nArray B\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cout<<b[i][j]; cout<<" "; } cout<<"\n"; } cout<<"\nSum of matrix:\n";

for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { cout<<c[i][j]; cout<<" "; } cout<<"\n"; } getch(); }

WAP to display elements of an array.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int a[10][10],m,n,i,j; cout<<"Enter size of matrix m*n:\n"; cin>>m>>n; cout<<"\nEnter elements of matrix A:\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; cout<<"\n"; } } cout<<"\nArray A\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) {

cout<<a[i][j]; cout<<" "; } cout<<"\n"; } getch(); }

WAP to calculate Sum and Average of an array.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int a[10][10],m,n,i,j,s=0,k=0; float l; cout<<"Enter size of matrix m*n:\n"; cin>>m>>n; cout<<"\nEnter elements of matrix A:\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; cout<<"\n"; k++; } } cout<<"\nArray A\n"; for(i=0;i<m;i++) {

for(j=0;j<n;j++) { cout<<a[i][j]; cout<<" "; } cout<<"\n"; } for(i=0;i<m;i++) { for(j=0;j<n;j++) { s=s+a[i][j]; } } l=s/k; cout<<"\nSum of Array:\n"<<s; cout<<"\nAverage of Array:\n"<<l; getch(); }

WAP to sort elements of an array using Bubble sort.

#include<conio.h> #include<stdio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int a[100],i,j,k,m; cout<<"Enter size of array:\n"; cin>>m; cout<<"\nEnter elements:\n"; for(i=0;i<m;i++) { cin>>a[i]; } cout<<"\nArranging in ascending order:\n"; for(i=0;i<m;i++) { for(j=0;j<i;j++) { if(a[i]<a[j]) { k=a[i];

a[i]=a[j]; a[j]=k; } } } for(i=0;i<m;i++) {cout<<a[i]<<" "; } getch(); }

WAP to calculate Factorial of a number.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int i,x,f=1; cout<<"Enter a no:\n"; cin>>x; for(i=1;i<=x;i++) { f=f*i; } cout<<"\nFactorial:\n"<<f; getch(); }

WAP to check whether a given number is Prime or not.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int i,x,k=0; cout<<"Enter a no:\n"; cin>>x; for(i=2;i<x/2;i++) { if(x%i==0) k++; } if(k==0) cout<<"\nPrime\n"; else cout<<"\nNot Prime\n"; getch(); }

WAP to generate Fibonacci series.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int i,x,a[100]; cout<<"Enter upto which place you want to generate series:\n"; cin>>x; a[0]=0; a[1]=1; for(i=2;i<x;i++) { a[i]=a[i-1]+a[i-2]; } cout<<"\nFibonacci series\n"; for(i=0;i<x;i++) { cout<<a[i]<<" "; } getch(); }

WAP to show function Overloading.

#include<iostream.h> #include<conio.h> #include<math.h> #include<stdio.h> void sum(int,int); void sum(double,double); void sum(char,char); main() { clrscr(); int a,b; double c,d; char e,f; cout<<"Enter 2 intigers:\n"; cin>>a>>b; cout<<"\nEnter 2 doubles:\n"; cin>>c>>d; cout<<"\nEnter 2 alphabets:\n"; cin>>e>>f; sum(a,b); sum(c,d); sum(e,f); getch();

return 0; } void sum(int x,int y) { cout<<"sum of two integer value="<<x+y<<endl; } void sum(double x,double y) { cout<<"sum of two double value="<<x+y<<endl; } void sum(char x,char y) { cout<<"sum of two char value="<<x+y<<endl; }

WAP to create a class and access member function of a class.

#include<conio.h> #include<stdio.h> #include<iostream.h> #include<math.h> class emp { int eno; char name[20],desg[20]; public: void input(); void output(); }; void main() { clrscr(); emp e; e.input(); cout<<"\n"; e.output(); getch(); } void emp::input() { cout<<"\nEmployee number:\n";

cin>>eno; cout<<"\nEmployee name:\n"; gets(name); cout<<"\nDesignation:\n"; gets(desg); } void emp::output() { cout<<"\nNumber:\n"<<eno; cout<<"\nName:\n"<<name; }

Write a program to convert the temperature in Fahrenheit to Celsius and vice-a-verse.

#include<conio.h> #include<iostream.h> #include<math.h> void main() { clrscr(); int f,c,a; cout<<"Conversions\n"; cout<<"1.Farenhite to Celcius\n"; cout<<"2.Celcius to Farenhite\n"; cout<<"Choose your option\n"; cin>>a; switch(a) { case 1:cout<<"\nEnter in Farenhite:\n"; cin>>f; c=((f-32)*5)/9; cout<<"\nCelcius:\n"<<c; break; case 2:cout<<"\nEnter in Celcius:\n"; cin>>c; f=((c*9)/5)+32;

cout<<"\nFarenhite:\n"<<f; break; } getch(); }

You might also like