0% found this document useful (0 votes)
5 views3 pages

LAB - PGM1 - Simple Calculator

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)
5 views3 pages

LAB - PGM1 - Simple Calculator

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/ 3

LAB Program 1

Simulation of a Simple Calculator.


Algorithm: To implement Commercial calculator.
Step 1: Start
Step 2: [Enter first number]
read num1
Step 3: [Enter Second number]
read num2
Step 4: [Enter Choice]
read choice
Step 5: [To perform addition]
if choice is equal to plus
add num1 and num2
print result
Step 6: [To perform subtraction]
if choice is equal to minus
subtract num2 from num1
print result
Step 7: [To perform multiplication]
if choice is equal to multiplication
multiply num1 and num2
print result
Step 8: [To perform division]
if choice is equal to division
divide num1 by num2
print result
Step 9: [To perform Modulus]
if choice is equal to modulus
divide num1 by num2
print result (remainder)
Step 10: Stop

Source Code:
#include<stdio.h>
void main()
{
float sum, sub, mul, div, a, b;
int choice,mod;
printf("Enter the values of a and b\n");
scanf("%f%f", &a,&b);
printf("Enter 1 for Addition,2 for Sutraction,3 for Multiplication, 4 for Division,5
for Mod\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("addition\n");
sum=a+b;
printf("%f ",sum); break;
case 2: printf("subtraction\n");
sub=a-b; printf("%f",sub);
break;
case 3: printf("Multiplication\n");
mul=a*b; printf("%f",mul);
break;
case 4: printf("Division\n");
if(b==0)
printf("Divide by zero error! please enter non-zero number");
else
{
div=a/b; printf("%f",div);
}
break;
case 5: printf("Modulus\n");
if(a<b)
mod=a;
else
mod=(int)a%(int)b;
printf("%d",mod);
break;
default: printf("Wrong choice, enter correct choice");
}
}

You might also like