Skip to main content

Simulation of a Simple Calculator | COMPUTER PROGRAMMING LABORATORY | 21CPL27/17


program

#include<stdio.h>

#include<stdlib.h>

void main()

{

    float a,b,c;

    char op;

    printf("enter the two operands\n");

    scanf("%f%f",&a,&b);

    printf("enter an operator\n");

    scanf("%f",&op);

    switch (op)

{

    case'+': c=a+b;

    printf("%f+%f=%f\n",a,b,c);

    break;

    case'-': c=a-b;

    printf("%f-%f=%f\n",a,b,c);

    break;

    case'*': c=a*b;

    printf("%f*%f=%f\n",a,b,c);

    break;

    case'/': if(b!=0)

{

    c=a/b;

    printf("%f/%f=%f\n",a,b,c);

    exit(0);

}

    else

    printf("division by 0 error");

    break;

    default:

    printf("enter valid operation");

}


Algorithm

Start 

Read 2 numbers as a and b

Read operator (+ or – or * or /) as op

If op is + then display a + b

Else If op is - then display a – b 

Else If op is * then display a * b 

Else If operator is / then 

 check if b is not equal to zero then display a / b 

 Otherwise display “Can not divide by 0” 

Stop


Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Select the option that is most nearly OPPOSITE in meaning to the word or phrase is given in bold. Birds are quarantined to prevent the spread of bird flu.

Select the option that is most nearly OPPOSITE in meaning to the word or phrase is given in bold. Birds are  quarantined  to prevent the spread of bird flu. immunized butchered secluded CORRECT mingled