Untitled
unknown
plain_text
6 months ago
2.9 kB
3
Indexable
#include<stdio.h> #include<math.h> void add(); void subtract(); void multiply(); void divide(); void power(); void square_root(); void factorial(); void sine(); void cosine(); void tangent(); int main() { int choice; do { printf("\nScientific Calculator:\n"); printf("1. Addition\n"); printf("2. Subtraction\n"); printf("3. Multiplication\n"); printf("4. Division\n"); printf("5. Power\n"); printf("6. Square Root\n"); printf("7. Sine\n"); printf("8. Cosine\n"); printf("9. Tangent\n"); printf("10. Exit\n"); printf("Choose any one operation: "); scanf("%d", &choice); switch (choice) { case 1: add(); break; case 2: subtract(); break; case 3: multiply(); break; case 4: divide(); break; case 5: power(); break; case 6: square_root(); break; case 7: sine(); break; case 8: cosine(); break; case 9: tangent(); break; case 10: printf("Exiting.\n"); break; default: printf("Invalid choice.\n"); } } while (choice!=11); return 0; } void add() { double a, b; printf("Enter two no: "); scanf("%lf %lf",&a,&b); printf("Result: %.2lf\n",a+b); } void subtract() { double a,b; printf("Enter two no: "); scanf("%lf %lf",&a,&b); printf("Result: %.2lf\n",a-b); } void multiply() { double a,b; printf("Enter two no: "); scanf("%lf %lf",&a,&b); printf("Result: %.2lf\n",a*b); } void divide() { double a,b; printf("Enter two no: "); scanf("%lf %lf",&a,&b); if (b!=0) printf("Result: %.2lf\n",a/b); else printf("Error!\n"); } void power() { double base, exp; printf("Enter base & exponent: "); scanf("%lf %lf", &base, &exp); printf("Result: %.2lf\n", pow(base,exp)); } void square_root() { double num; printf("Enter a number: "); scanf("%lf", &num); if (num >= 0) printf("Result: %.2lf\n", sqrt(num)); else printf("Error! negative number.\n"); } void sine() { double angle; printf("Enter an angle in degrees: "); scanf("%lf",&angle); double radians=angle*(M_PI/180.0); printf("sin(%.2lf)=%.2lf\n", angle, sin(radians)); } void cosine() { double angle; printf("Enter an angle in degrees: "); scanf("%lf",&angle); double radians=angle*(M_PI/180.0); printf("cos(%.2lf)=%.2lf\n",angle,cos(radians)); } void tangent() { double angle; printf("Enter an angle in degrees: "); scanf("%lf",&angle); double radians=angle*(M_PI/180.0); if ((int)angle%180==90) printf("tan(%.2lf) is undefined.\n",angle); else printf("tan(%.2lf)=%.2lf\n",angle,tan(radians)); }
Editor is loading...
Leave a Comment