You are on page 1of 8

#include<stdio.

h>
#include<conio.h>
#include<math.h>
#include<Windows.h>
void menu();
void arithematic();
void trignometric();
void quardratic();
void threevariables();
void linearequation();
void matrix();
void main()
{int r=0;
do{char
ch=65,a[8]={0,0,0,0,0,0,0,0},password[8]={'m','u','n','e','e','b',0,0};
int i=0;

printf("\nENTER PASSWORD TO UNLOCK THE CALCULATOR\n");


while (ch!=13)
{ch=getch();
if(ch==13)
break;
a[i]=ch;
printf("*");
i++;
}
if(a[0]==password[0]&&a[1]==password[1]&&a[2]==password[2]&&a[3]==password[3]
&&a[4]==password[4]&&a[5]==password[5]&&a[6]==password[6]&&a[7]==password[7])
{printf("\naccess granted");
system("cls");
r=1;}

}while(r==0);
menu();

void menu()
{int choice=0;
char ch;
do{system("cls");
printf("\nCHOICE THE FUNCTION TO BE PERFORMED\n");
printf("\n1.Arithematic");
printf("\n2.trignometric Funtions\n3.Quadratic Equation Solver\n4.Equation of
three unknowns\n5.linear equation for three variables\n");
printf("6.Matrix\n");
scanf("%d",&choice);
switch(choice)
{case 1:
{arithematic();
break;}
case 2:
{trignometric();
break;}
case 3:
{quardratic();
break;}
case 4:
{threevariables();
break;}
case 5:

{linearequation();
break;}
case 6:
{
matrix();
break;}
default:
printf("\nWRONG ENTERY\n");
break;
}
printf("\nTo run the menu again\n enterY\n");
ch=getch();}
while(ch=='y'||ch=='Y');
}

void arithematic()
{
int a,b;
char c;
printf("\nEnter the expression for the arithematic calculations\n");
scanf("%d %c %d",&a,&c,&b);
switch(c)
{case '+':
{ printf("%d",a+b);
break;}
case '-':
{ printf("%d",a-b);
break;}
case '/':
{if(b!=0)
printf("%d",a/b);
else
break;}
case '%':
{ if(b!=0)
printf("%d",a%b);
else
break;}
case '*':
{ printf("%d",a*b);
break;}
default:
{ printf("\nINVALID ENTERY\n");
break;}
}}
void trignometric()
{int ch;
float radian,angle;
printf("\nENTER THE VALUE IN DEGREES\n");
scanf("%f",&angle);
radian=angle*3.14159/180;
printf("Enter (1) for sine\nenter (2) for cosine\n enter (3) for tan\n");
ch=getch();
switch(ch)
{case 49:
{printf("%f",sin(radian));
break;
}
case 50:
{printf("%f",cos(radian));
break;
}
case 51:
{printf("%f",tan(radian));
break;}
default:
printf("\nWRONG ENTERY\N");
}}

void quardratic()
{
float a,b,c,determinent,r1,r2,real,imag;
printf("Enter co efficients a b and c:");
scanf("%f%f%f",&a,&b,&c);
determinent=b*b-4*a*c;
if(determinent>0)
{
r1=(-b+sqrt(determinent))/(2*a);
r2=(-b-sqrt(determinent))/(2*a);
printf("Roots are :%f and %f",r1,r2);}
else if(determinent==0)
{r1=r2=-b/(2*a);
printf("Roots are :%f %f" ,r1,r2);}
else {real=-b/(2*a);
imag=sqrt(-determinent)/(2*a);
printf("The roots of the equation are: %f+%fi %f-%fi",real,imag,real,imag);}

}
void matrix()
{int m;

printf("Select an option from following menu:\n");


printf("1.Addition\n");
printf("2.Subtraction\n");
printf("3.Multiplication\n");
printf("4.Transpose\n");
scanf("%d",&m);
switch(m)
{
case 1 :
{
int r1,r2,c1,c2;
int A[5][5],B[5][5],C[5][5];
printf("Enter order of 1st matrix:\n");
scanf("%d%d",&r1,&c1);
printf("Enter order of matrix:\n");
scanf("%d%d",&r2,&c2);
if(r1==r2&&c1==c2)
{
printf("Enter Elements of 1st Matrix:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
scanf("%d",&A[i][j]);
}
printf("Enter Elements of 2nd Matrix:\n");
for(int i=0;i<r2;i++)
{
for(int j=0;j<c2;j++)
scanf("%d",&B[i][j]);
}
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
C[i][j]=A[i][j]+B[i][j];
}
printf("First Matrix is:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
printf("%d\t",&A[i][j]);
}
printf("\n");
}
printf("Second Matrix is:\n");
for(int i=0;i<r2;i++)
{
for(int j=0;j<c2;j++)
{
printf("%d\t",&B[i][j]);
}
printf("\n");
}
printf("Resultant Matrix is:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
printf("%d\t",C[i][j]);
}
printf("\n");
}
}
else
printf("Maximum order should be 5X5.....");
break;}
case 2 :
{ int r1,r2,c1,c2;
int A[5][5],B[5][5],C[5][5];
printf("Enter order of 1st matrix:\n");
scanf("%d%d",&r1,&c1);
printf("Enter order of matrix:\n");
scanf("%d%d",&r2,&c2);
if(r1==r2&&c1==c2)
{
printf("Enter Elements of 1st Matrix:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
scanf("%d",&A[i][j]);
}
printf("Enter Elements of 2nd Matrix:\n");
for(int i=0;i<r2;i++)
{
for(int j=0;j<c2;j++)
scanf("%d",&B[i][j]);
}
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
C[i][j]=A[i][j]-B[i][j];
}
printf("First Matrix is:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
printf("%d\t",&A[i][j]);
}
printf("\n");
}
printf("Second Matrix is:\n");
for(int i=0;i<r2;i++)
{
for(int j=0;j<c2;j++)
{
printf("%d\t",&B[i][j]);
}
printf("\n");
}
printf("Resultant Matrix is:\n");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
printf("%d\t",C[i][j]);
}
printf("\n");
}
}
else
printf("Maximum order should be 5X5.....");
break;
}
case 3 :
{
int mata[10][10], matb[10][10], matc[10][10] ;
int i, j, k, row1, col1, row2, col2 ;
printf("Enter the order of first matrix : ") ;
scanf("%d %d", &row1, &col1) ;
printf("\nEnter the order of second matrix : ") ;
scanf("%d %d", &row2, &col2) ;
if(col1 == row2)
{
printf("\nEnter the elements of first matrix : \n\n") ;
for(i = 0 ; i < row1 ; i++)
for(j = 0 ; j < col1 ; j++)
scanf("%d", &mata[i][j]) ;
printf("\nEnter the elements of second matrix : \n\n") ;
for(i = 0 ; i < row2 ; i++)
for(j = 0 ; j < col2 ; j++)
scanf("%d", &matb[i][j]) ;
for(i = 0 ; i < row1 ; i++)
{
for(j = 0 ; j < col2 ; j++)
{
matc[i][j] = 0 ;
for(k = 0 ; k < col1 ; k++)
matc[i][j] = matc[i][j] + mata[i][k] * matb[k][j] ;
}
}
printf("\nThe resultant matrix is : \n\n") ;
for(i = 0 ; i < row1 ; i++)
{
for(j = 0 ; j < col2 ; j++)
{
printf("%d \t", matc[i][j]) ;
}
printf("\n") ;
}
}
else
printf("\nMatrix Multiplication is not possible ...") ;
break;
}
case 4 :
{
int mat[10][10] ;
int i, j, row, col ;
printf("Enter the order of the matrix : ") ;
scanf("%d %d", &row, &col) ;
printf("\nEnter the elements of the matrix : \n\n") ;
for(i = 0 ; i < row ; i++)
for(j = 0 ; j < col ; j++)
scanf("%d", &mat[i][j]) ;
printf("\nThe transpose matrix is : \n\n") ;
for(i = 0 ; i < col ; i++)
{
for(j = 0 ; j < row ; j++)
{
printf("%d \t", mat[j][i]) ;
}
printf("\n") ;
}
break;
}
default :
printf("Invalid Entry.........");
}

}
void threevariables()
{float a,b,c,d,l,m,n,k,p,D,q,r,s,x,y,z;
printf("\nPROGRAM TO SOLVE THREE VARIABLE LINEAR SIMULTANEOUS EQUATION\n");

printf("\nThe equations are of the FORM:ax+by+cz+d=0\n ,lx+my+nz+k=0\n AND


px+qy+rz+s=0\n");

printf("\nEnter the coefficients in the order\t a,b,c,d,l,m,n,k,p,q,r,s");


scanf("%f%f%f%f%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&l,&m,&n,&k,&p,&q,&r,&s);
printf("\nThe equations you have input are:\n");

printf("\n %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",a,b,c,d);


printf(" \n %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",l,m,n,k);
printf("\n %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",p,q,r,s);

D = (a*m*r+b*p*n+c*l*q)-(a*n*q+b*l*r+c*m*p);
x = ((b*r*k+c*m*s+d*n*q)-(b*n*s+c*q*k+d*m*r))/D;
y = ((a*n*s+c*p*k+d*l*r)-(a*r*k+c*l*s+d*n*p))/D;
z = ((a*q*k+b*l*s+d*m*p)-(a*m*s+b*p*k+d*l*q))/D;

printf("\nThe solutions to the above three equations are :\n");


printf(" \n x = %5.2f\ny = %5.2f\nz = %5.2f",x,y,z);
}

void linearequation()

{int num=0,t,v=0,c=0,pt=0,m,p[10],pwr[10];
float a[10]={0,0,0},var[10],sol[10];
char ch=0,sign[10],variable[10]={0,0,0,0,0,0,0,0,0,0};
printf("Enter a linear eq such as 2x+3m+9d\n");
do{
scanf("%c",&ch);
if(ch==46)
pt=1;
else if(ch>=48&&ch<=57)
{ t=ch-48;
a[num]=10*a[num]+t;
if(pt>0)
pt++;}
else if(ch=='+'||ch=='-')
{sign[num]=ch;
if(pt>0)
{pt=pt-1;
m=pow(10.0,pt);

a[num]=a[num]/m;}
num++;
pt=0;}
else if(ch=='^'||p[num]==1)
{p[num]==1;
if(ch!='^')
{t=ch-48;
pwr[num]=10*pwr[num]+t;}}
else if(ch>=65&&ch<=90||ch>=97&&ch<=122)
variable[num]=ch;

else if(ch==10)
{if(pt>0)
{pt=pt-1;
m=pow(10.0,pt);

a[num]=a[num]/m;}

pt=0;
break;}

}
while(ch!=13);

for(int i=0;i<=num;i++)
{if(variable[i]!=0)
{printf("Enter the value of %c",variable[i]);
scanf("%f",&var[i]);}}
for(int j=0;j<=num;j++)
{if(a[j]==0)
sol[j]=var[j];
else if(variable[j]==0)
sol[j]=a[j];
else
sol[j]=a[j]*var[j];
}
for(int k=0;k<=num;k++)
switch(sign[k])
{case'+':
{sol[k+1]=sol[k]+sol[k+1];
c=k;
break;}
case'-':
{sol[k+1]=sol[k]-sol[k+1];
c=k;
break;}
}
printf("%f",sol[c+1]);

You might also like