Você está na página 1de 10

program 1

#include<iostream.h>
#include<conio.h>
void main()
{ float p,c,m,s,e,t,z ;
cout<<"enter marks in physics-";
cin>>p;
cout<<"enter marks in chemistry-";
cin>>c;
cout<<"enter marks in maths-";
cin>>m;
cout<<"enter marks in computer sceince-";
cin>>s;
cout<<"enter marks in english-";
cin>>e;
z=p+c+m+s+e;
cout<<"total marks-"<<z;
t=z/5;
cout<<"total percentage="<<t;
if(t>90)
cout<<"\n your grade is A1";
else if(t>80)
cout<<"\n your grade is A2";
else if (t>70)
cout<<"\n your grade is B1";
else if (t>60)
cout<<"\n your grade is B2";
else if(t>50)
cout<<"\n your grade is C1";
else cout<<"fail";
getch();
}
program -2
to find the largest of three numbers
#include<iostream.h>
#include<conio.h>
void main()
{ float a,b,c,max;
cout <<"enter the three numbers";
cin>>a>>b>>c;
if(a>b && a>c)
max=a;
else if(b>c)
max=b;
else max=c;
getch();
}
program 3
to find roots of quadratic equation
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main ()

{ float a,b,c,r,d,r1,r2;
cout<<"enter coefficient of quadratic equation";
cin>>a>>b>>c;
d=b*b-(4*a*c);
if(d>0)
{cout<<"roots are real and distinct";
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
cout<<"the roots are"<<r1<<"and"<<r2;
}
else if(d==0)
{cout<<"the roots are real and equal";
r=-b/(2*a);
cout<<"roots are"<<r;
}
else cout <<"roots are imaginary";
getch();
}
program 4
to convert from farenheit to celcius
to convert from celcius to farenheit
#include<iostream.h>
#include<conio.h>
void main()
{int choice,operation;
cout<<"1.from celsius to farenheit \n";
cout<<"2.from farenheit to celcius ";
cin>>choice;
switch (choice)
{case 1: float c;
cout<<"enter temperature in celcius \n";
cin>>c;
operation=((9.0/5)*c)+32;
cout<<"the temperature in farenheit is";
cout<<operation;
break;
case 2 :float f;
cout<<"enter the temperature in farenheit \n";
cin>>f;
operation=((f-32)*(5.0/9));
cout<<"temperature in celcius is";
cin>>operation;
break ;
default:
cout <<"invalid choice";
}getch() ;
}

program 5
//todisplay a functioning 4 function calculater//
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main()

{float A,S,D,M;
int a,b,c;
cout<<"enter the values of 2 numbers";
cin>>a>>b;
cout<<"choose your option \n 1.addition \n 2.subtraction \n 3.division \n 4.mult
iplication";
cin>>c;
switch(c)
{case'1':cout<<"your choice was addition";
A=a+b;
cout<<A;
break;
case'2':cout<<"your choice was subtraction";
if(a>b)
S=a-b;
else S=b-a;
cout<<S;
break;
case'3':cout<<"your choice was division";
D=a/b;
cout<<"";
cout<<setprecision(2)<<D;
break;
case'4':cout<<"your choice was multiplication";
M=a*b;
cout<<"";

cout<<M;
break;
default :"wrong choice entered" ;
}
getch();
}

PROGRAMME 6
to check whether a number is prime or not
#include<iostream.h>
#include<conio.h>
void main()
{int n,i,c=0;
cout<<"enter a number";
cin>>n;
for(i=2;i<n;i++)
{if(n%i==0)
c++;
}if(c==0)
cout<<"the given number is a prime number";
else
cout<<"the given number is not a prime number:";
getch();
}

programe 8
// to calculate the area of a traingle, circle and rectangle

#include<iostream.h>
#include<conio.h>
void main()
{float a,b,r,area;
char ch;
cout<<"\n 1.area of traingle in 2. area of circle 3.area of rectangle in select
your choice";
cin>>ch;
switch(ch)
{case'1':cout<<"\n enter base and height of triangle";
cin>>a>>b;
area=0.5*a*b;
cout<<"\n area of traingle="<<area;
break;
case'2':cout<<"\n enter the radius of the circle";
cin>>r;
area=3.14*r*r;
cout<<"\n area of circle is="<<area;
break;
case'3':cout<< "\n enter the length and breadth of the rectangle";
cin>>a>>b;
cout<<"\n area of rectangle="<<a*b;
break;
default:cout<<"\n invalid choice:";
}getch();
}

programme 9
to find HCF and LCM of 2 nos
#include<iostream.h>
#include<conio.h>
void main()
{int a,b,HCF,LCM,n1,n2;
cout<<"enter 2 numbers";
cin>>n1>>n2;
a=n1;
b=n2;
while(a!=b)
{if(a>b)
a=a-b;
else b=b-a;
}
HCF=a;
LCM=(n1*n2)/HCF;
cout<<"HCF="<<HCF<<"\n LCM="<<LCM;
getch();
}
PROGRAMME 10
find a number form an array
#include<iostream.h>
#include<conio.h>
void main()

{int A[20],m,n,i;
cout<<"enter the value of n";
cin>>n;
cout<<"start entering"<<n<<"numbers";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\n enter a number to be searched";
cin>>m;
for(i=0;i<n;i++)
if(m==A[i])
{cout<<"element found in array and is the element" ;
cout<<(i+1)<<"of array";
}
cout<<"element not found in the list";
getch();
}


PROGRAMME 12
to reverse an array
#include<iostream.h>
#include<conio.h>
void main()
{int A[50],t,n,i;
cout<<"enter the size of array:" ;
cin>>n;
cout<<"enter the array elements";
for(i=0;i<n;i++)
cin>>A[i];
for(i=0;i<n/2;i++)
{t=A[i];
A[i]=A[n-i-1];
A[n-i-1]=t;
}
cout<<"Array elements after reversing:";
for(i=0;i<n;i++)
cout<<A[i]<<"\t";
getch();
}
PROGRAMME 12
pALLINDROME
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{char str1[20],str2[20];
cout<<"enter a string";
cin>>str1;
gets(str1);
strcpy(str2,str1);

strrev(str2);
if(strcmpi(str1,str2)==0)
cout<<str1<<"is a pallindrome";
else
cout<<str1<<"is not a pallindrame";
getch();
}
PROGRAMME 13
sum of principle and secondary diagnal elemts of matrix
#include<iostream.h>
#include<conio.h>
void main()
{int A[5][5],m,n,i,j,sump=0,sums=0;
cout<<"enter the order of the matrix";
cin>>m>>n;
cout<<"enter the elements of the matrix";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
if(m==n)
for(i=0;i<m;i++)
{sump=sump+A[i][j];
sums=sums+A[i][m-i-1];
cout<<"sum of principle diagonal elements is"<<sump ;
cout<<"\n sum if the secondary diagpnal elements is "<<sums;
}
else;
cout<<"not a square matrix" ;
getch();
}

programm 14
to find whether a matrix is symmetric or not
#include<iostream.h>
#include<conio.h>
void main()
{int A[10][10],i,j,n,m,p=1;
cout<<"enter order of matrix";
cin>>m>>n;
cout<<"enter the matrix";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
if(m==n)
{for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(A[i][j]!=A[j][i])
{p=0;
break;
for(i=0;i<m;i++)
cout<<A[i][j]<<"\t";

cout<<"\n";
cout<<"matrix is symmetric";}
else cout<<"wrong order of matrix";}
getch();
}
PROGRAM 15
to add two matrix
#include<iostream.h>
#include<conio.h>
void main()
{int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q ;
cout<<" enter the order of matrix A";
cin>>m>>n;
cout<<"\n enter the order of matrix B:";
cin>>p>>q;
if((m==p)&&(n==p))
{cout<<"\n input matrix -a: \n";
for(i=0;i<m;i++)
for(j=0;i<n;j++)
cin>>a[i][j];
cout<<"\n input matrix-b: \n";
for(i=0;i<p;i++)
for(j=0;j<q;j++)
cin>>b[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
cout<<"\n the sum of matrix A and B is : \n";
for(i=0;j<m;i++)
{cout<<"\n";
for(j=0;j<n;j++)
cout<<""<<c[i][j];
}
}
else
{cout<<"\n wrong order of matrix ";}
getch();
}
PROGRAM 16
to find row sum and column sum
#include<iostream.h>
#include<conio.h>
void main ()
{int A[10][10],i,j,m,n,rsum,csum;
cout<<"enter the order of matrix";
cin>>m>>n;
if(m==n)
{cout<<"\n enter matrix";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
for(i=0;i<m;i++)

{for(j=0;j<n;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
for(j=0;j<n;j++)
{csum=0;
rsum=0;
for(i=0;i<m;i++)
{csum=csum+A[i][j];
rsum=rsum+A[j][i];
}
cout<<"\n sum of row"<<(j+1)<<"="<<rsum;
cout<<"\n sum of column"<<(j+1)<<"="<<csum;
getch();
}}}

program 17
to find the product of two matix
#include<iostream.h>
#include<conio.h>
void main()
{int A[10][10],B[10][10],C[10][10],c,i,j,m,n,p,q;
cout<<"\n enter the order of matrix 1";
cin>>m>>n;
cout<<"\n enter the order of matrix Z";
cin>>p>>q;
cout<<"enter the elements of matrix 1";
for(i=0;i<m;i++)
for(j=0;j<n;i++)
cin>>A[i][j];
cout<<"enter the elements of matrix Z";
for(i=0;i<p;i++)
for(j=0;j<q;j++)
cin>>B[i][j];
if(n==p)
{for(i=0;i<m;i++)
for(j=0;j<n;j++)
{C[i][j]=0;
for(int k=0;k<n;k++)
C[i][j]=A[i][k]*B[k][j];
}
cout<<"in matrix1:";
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
cout<<"\n matrix Z:";
for(i=0;i<p;i++)
{for(j=0; j<q;j++)
cout<<C[i][j]<<"\t";
cout<<"\n";
}
getch();
}}

PROGRAM 18
to find the largest number of element in an array
#include<iostream.h>
#include<conio.h>
{int large(int B[10],int n);
int L;
L=B[10];
for(int i=0;i<n;i++)
if (L<B[i]);
L=(B[i]);
return L;
}
void main()
{int A[10],n,i;
cout<<"How many numbers do you want to enter?";
cin>>n;
cout<<"enter the numbers";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\n largest number is "<<large(A,n);
getch();
}

PROGRAM 19
to find factorial of a number using function
#include<iostream.h)
#include<conio.h>
long fact(int n)
{long int fact=1;
int i;
for(i=1;i<=n;i++)
fact=fact*i;
return fact;
}
void main()
{int n;
cout<<"\n enter a number to find its factorial";
cin>>n;
cout<<n<<"!="<<fact(n);
getch();
}

PROGRAM 20
STRUCTURE OF EMPLOYEES
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct employee
{int eno;
char ename[50];

char designation[50];
float basic;
float netsal;
};
void main()
{float DA,HRA,gross,PF;
cout<<"\n input employee info";
employee e1;
cout <<"\n enter employee no:";
cin>>e1.eno;
cout<<"enter employee name";
gets(e1.ename);
cout<<"enter employees designation";
gets(e1.designation);
cout<<"enter basic salary";
cin>>e1.basic;
DA=0.3*e1.basic;
HRA=0.2*e1.basic;
gross=e1.basic+DA+HRA;
PF=0.12*gross;
e1.netsal=gross-PF;
cout<<"employee no: "<<e1.eno;
cout<<"\n";
cout<<"employee name:"<<e1.ename;
cout<<"\n employee designation:"<<e1.designation;
cout<<"in net salary: "<<e1.netsal;
getch();
}
program 7
to display fibonacci series
#include<conio.h>
#include<iostream.h>
void main()
{int a,b,c,n;
a=0;
b=1;
cout<<"how many values ? \n " ;
cin>>n ;
cout<<"fibonacci series \n " ;
cout<<a<<" "<<b;
for(int i=2;i<n;i++)
{c=a+b;
cout<<" "<<c;
a=b;
b=c;
}getch() ;
}

Você também pode gostar