KEMBAR78
Simple Calculator | PDF
0% found this document useful (0 votes)
57 views1 page

Simple Calculator

This document is a C program for a simple calculator that performs basic arithmetic operations: addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then calculates and displays the result based on the chosen operation. If an invalid operation is entered, it outputs an error message.

Uploaded by

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

Simple Calculator

This document is a C program for a simple calculator that performs basic arithmetic operations: addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then calculates and displays the result based on the chosen operation. If an invalid operation is entered, it outputs an error message.

Uploaded by

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

#include <stdio.

h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{ int num1;
int num2;
char operator;
float result;
printf("Welcome to Nathan's Calculator\n");
printf("Please choose one of the following operations: '+', '-', '*', '/': ");
scanf("%c",&operator);
printf("Please enter the first number: ");
scanf("%d",&num1);
printf("\nPlease enter the second number: ");
scanf("%d",&num2);
switch(operator)
{
case '+':
result = num1 + num2;
printf("The sum of the two numbers is: %.2f", result);
break;

case '-':
result = num1 - num2;
printf("The difference of the two numbers is: %.2f", result);
break;

case '*':
result = num1 * num2;
printf("The product of the two numbers is: %.2f", result);
break;

case '/':
result = num1/num2;
printf("The quotient of the two numbers is: %.2f", result);
break;

default:
printf("Invalid operation");
}
return 0;
}

You might also like