Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Date: 29-11-2010

Assignment # 03 Submitted to: Miss Farzana Submitted by


Waqas Mehmood Raja Arslan Akbar Raja Humayun Jahangir Hassan Qadeer

Dr. A. Q. Khan Institute of Computer Sciences & Information Technology KRL, Kahuta
1 Computer Programming

Scientific calculator using functions.


#include <stdio.h> #include <conio.h> #include <math.h> int power(int,int); float inverse(float); double si(float); double co(float); double ta(float); int fact(int); void main() { int funct,num,num1,num2,re,re1,re2,re3; float re_f,num_f,re_f1; double re_d,re_d1,num_d; clrscr(); printf("Enter 1 to find Square Root of any number:\n"); printf("Enter 2 to find Raise to Power of Any Number:\n"); printf("Enter 3 to find Inverse of any number:\n"); printf("Enter 4 to find Fictorial of any number:\n"); printf("Enter 5 to find Natural log of any number:\n"); printf("Enter 6 to find log of any number:\n"); printf("Enter 7 to find Sin of any number:\n"); printf("Enter 8 to find Cos of any number:\n"); printf("Enter 9 to find Tan of any number:\n"); printf("Enter 10 to find Cot of any number:\n"); printf("Enter 11 to find Cosec of any number:\n"); printf("Enter 12 to find Sec of any number:\n"); scanf("%d",&funct); switch(funct) { case 1: printf("Enter Number to find its Square Root:"); scanf("%f",&num_f); re_f=sqrt(num_f); printf("Square Root of %.f is %.2f",num_f,re_f); break; case 2: printf("Enter Number:"); scanf("%d",&num); printf("Enter Power:"); scanf("%d",&num1); re=power(num,num1); printf("%d raise to power %d is: %d",num,num1,re); 2 Computer Programming

break; case 3: printf("Enter Number to Find its inverse:"); scanf("%f",&num_f); re_f=inverse(num_f); printf("Inverse of %.f is %.3f",num_f,re_f); break; case 4: printf("Enter Number to find its factorial:"); scanf("%d",&num); re=fact(num); printf("Factorial of %d is %d",num,re); break; case 5: printf("Enter Number to Find its Natural Log:"); scanf("%f",&num_f); re_d=log(num_f); printf("Natural Log of %.2f is %.2f",num_f,re_d); break; case 6: printf("Enter Number to Find its Log:"); scanf("%f",&num_f); re_d=log10(num_f); printf("Log of %.2f is %.2f",num_f,re_d); break; case 7: printf("Enter Number to Find its Sin Value:"); scanf("%f",&num_f); re_d=si(num_f); printf("Sin of %.f is %.3f",num_f,re_d); break; case 8: printf("Enter Number to Find its Cos Value:"); scanf("%f",&num_f); re_d=co(num_f); printf("cos of %.f is %.3f",num_f,re_d); break; case 9: printf("Enter Number to Find its Tan Value:"); scanf("%f",&num_f); re_d=ta(num_f); printf("Tangent of %.f is %.3f",num_f,re_d); break; case 10: printf("Enter Number to Find its Cotagant Value:"); scanf("%f",&num_f); re_d=ta(num_f); re_d1=1/re_d; 3 Computer Programming

printf("Cotangent of %f is %f",num_f,re_d1); break; case 11: printf("Enter Number to Find its Cosec Value:"); scanf("%f",&num_f); re_d=si(num_f); re_d1=1/re_d; printf("Cosec of %f is %f",num_f,re_d1); break; case 12: printf("Enter Number to Find its Sec Value:"); scanf("%f",&num_f); re_d=co(num_f); re_d1=1/re_d; printf("Sec of %f is %f",num_f,re_d1); break; default: printf("Invalid Number"); } getch(); } int power(int x, int y) { int z; z=pow(x,y); return z; } float inverse(float x) { float z; z=1/x; return z; } double si(float x) { double z; z=sin(x); return z; } double co(float x) { double z; z=cos(x); return z; } double ta(float x) { double z; 4 Computer Programming

z=tan(x); return z; } int fact(int x) { int y,z=1; for(y=1;y<=x;y++) { z=z*y; } return z; }

5 Computer Programming

You might also like