Lab 1 - POP Using C
Lab 1 - POP Using C
Algorithm:
Step 1: START
Step 2 : Read two numbers
say num1 and num2
Step 3: Read arithmetic operator(+,-,*,/)
say it as op
Step 4: Check if op is matching with '+'
Compute result=num1+num2
display result
Check if op is matching with '-'
Compute result=num1-num2
display result
Check if op is matching with '*'
Compute result=num1*num2
display result
Check if op is matching with '/'
Check if num2 is 0
Display the given operation cannot be performed
else
Compute result=num1/num2
display result
else
display Error Message
Step 5: STOP
Flowchart:
Simple Calculator
Program:
#include<stdio.h>
#include<stdlib.h>
void main()
{
float num1, num2, result;
char op;
printf(“Enter the operator (+,-,*./) \n”);
scanf(“%c”, &op);
printf(“Please enter two numbers:\n”);
scanf(“%f %f”, &num1, &num2);
if(op = = ’+’ )
{
result = num1 + num2;
printf(“Result is %0.2f \n”, result);
}
else if(op = = ’-’ )
{
result = num1 - num2;
printf(“Result is %0.2f \n”, result);
}
else if(op = = ’*’ )
{
result = num1* num2;
printf(“Result is %0.2f \n”, result);
}
else if(op = = ‘/ ’ )
{
if(num2 = = 0)
{
OUTPUT:
Case 1: Enter the operator (+,-,*,/)
+
Please enter two numbers: 4 2
Result is 6.00