0% found this document useful (0 votes)
10 views6 pages

Cse 115

This document is a C program that implements a simple calculator with a graphical display. It allows users to perform basic arithmetic operations as well as advanced functions like square root, logarithm, and trigonometric calculations. The program prompts the user for an operation and the necessary inputs, then displays the result of the calculation.

Uploaded by

ahmaad.nova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Cse 115

This document is a C program that implements a simple calculator with a graphical display. It allows users to perform basic arithmetic operations as well as advanced functions like square root, logarithm, and trigonometric calculations. The program prompts the user for an operation and the necessary inputs, then displays the result of the calculation.

Uploaded by

ahmaad.nova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

h>
#include <math.h>

void displayCalculator() {
printf(" _______________________\n");
printf("| _______ |\n");
printf("| | | 0. | |\n");
printf("| |_______| |\n");
printf("| _ _ _ _ |\n");
printf("| | 7 | | 8 | | 9 | | / |\n");
printf("| |_| |_| |_| |_ |\n");
printf("| _ _ _ _ |\n");
printf("| | 4 | | 5 | | 6 | | * |\n");
printf("| |_| |_| |_| |_ |\n");
printf("| _ _ _ _ |\n");
printf("| | 1 | | 2 | | 3 | | - |\n");
printf("| |_| |_| |_| |_ |\n");
printf("| _ _ _ _ |\n");
printf("| | . | | 0 | | = | | + |\n");
printf("| |_| |_| |_| |_ |\n");
printf("|_______ ______________ |\n");
printf("| sqrt | log |\n");
printf("| sin | cos | tan |\n");
printf("|_______________________|\n");
}

int main() {
char operation[10];
double num1, num2, result;

displayCalculator();
printf("\nEnter operation (+, -, *, /, sqrt, log, sin, cos,
tan): ");
scanf("%s", operation);

if (operation[0] == 's' && operation[1] == 'q' &&


operation[2] == 'r' && operation[3] == 't' &&
operation[4] == '\0') {
printf("Enter number: ");
scanf("%lf", &num1);
result = sqrt(num1);
printf("Result: %.2lf\n", result);
} else if (operation[0] == 'l' && operation[1] == 'o' &&
operation[2] == 'g' && operation[3] == '\0') {
printf("Enter number: ");
scanf("%lf", &num1);
result = log(num1);
printf("Result: %.2lf\n", result);
} else if (operation[0] == 's' && operation[1] == 'i' &&
operation[2] == 'n' && operation[3] == '\0') {
printf("Enter angle in radians: ");
scanf("%lf", &num1);
result = sin(num1);
printf("Result: %.2lf\n", result);
} else if (operation[0] == 'c' && operation[1] == 'o' &&
operation[2] == 's' && operation[3] == '\0') {
printf("Enter angle in radians: ");
scanf("%lf", &num1);
result = cos(num1);
printf("Result: %.2lf\n", result);
} else if (operation[0] == 't' && operation[1] == 'a' &&
operation[2] == 'n' && operation[3] == '\0') {
printf("Enter angle in radians: ");
scanf("%lf", &num1);
result = tan(num1);
printf("Result: %.2lf\n", result);
} else {

switch (operation[0]) {
case '+':
case '-':
case '*':
case '/':
printf("Enter first number: ");
scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);

if (operation[0] == '+') {
result = num1 + num2;
} else if (operation[0] == '-') {
result = num1 - num2;
} else if (operation[0] == '*') {
result = num1 * num2;
} else if (operation[0] == '/') {
if (num2 != 0) {
result = num1 / num2;
} else {
printf("Error! Division by zero is
undefined.\n");
return 1;
}
}
printf("Result: %.2lf\n", result);
break;

default:
printf("Error!\n");
return 1;
}
}

return 0;
}
Output

You might also like