0% found this document useful (0 votes)
6 views

Program_1

Program 1

Uploaded by

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

Program_1

Program 1

Uploaded by

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

SIMULATION OF A SIMPLE CALCULATOR

AIM: To write a C Program To Simulate A Simple Calculator

ALGORITHM

Step 1: Start
Step 2: Read the value of operator op.
Step 3: Read the values of num1 and num2.
Step 4: Verify op value by using switch statement
if op=’+’ then goto step 5 (or)
if op=’-’ then goto step 6 (or)
if op=’*’ then goto step 7 (or)
if op=’/’ then goto step 8 (or)
otherwise goto step 9
Step 5: if op=’+’ then compute result=num1+num2
print result and goto step 10
Step 6: if op=’-’ then compute result=num1-num2
print result and goto step 10
Step 7: if op=’*’ then compute result=num1*num2
print result and goto step 10
Step 8: if op=’/’ then compute divresult=num1/num2
print divresult and goto step 10
Step 9: if op value is other than above options then
print “Invalid input, Try again” goto step 10
Step 10: Stop
FLOWCHART
PROGRAM

#include <stdio.h>
#include <conio.h>
void main()
{
int num1,num2,result;
float divresult;
char op;
clrscr();
printf("Enter the operation to be done \n");
scanf("%c",&op);
printf("Enter the value of num1 and num2 \n");
scanf("%d%d",&num1,&num2);
switch(op)
{
case '+': result = num1 + num2;
printf(“Addition=%d\n”,result);
break;
case '-': result = num1 - num2;
printf(“Subtraction=%d\n”,result);
break;
case '*': result = num1 * num2;
printf(“Multiplication=%d\n”,result);
break;
case '/': divresult = num1 / (float)num2;
printf(“Division=%.2f\n”,divresult);
break;
default: printf("Invalid Input ,Try Again\n");
}
getch();
}
OUTPUT 20
First Run: 30
Enter the operation to be done Multiplication=600
+
Enter the value of num1 and num2
Fourth Run:
10
Enter the operation to be done
20
/
Addition=30
Enter the value of num1 and num2
40
Second Run:
50
Enter the operation to be done
Division=0.80
-
Enter the value of num1 and num2
Fifth Run:
10
Enter the operation to be done
20
@
Subtraction=-10
Enter the value of num1 and num2
40
Third Run:
50
Enter the operation to be done
Invalid Input ,Try Again
*
Enter the value of num1 and num2

RESULT: Thus, the program to implement the simple calculator has been executed
successfully and the output was verified.

You might also like