Skip to main content

Write a program to do the following operations:


6.
Write a program to do the following operations:
--Read any two positive integer operands (say op1 & op2) and one character               type operator (say opr). Note that opr is any mathematical operator.
--Depending upon the operator, do the appropriate operation. e.g. if opr is '+'                then the display the value obtained by evaluating the expression (op1 + op2)


#include<stdio.h>
#include<conio.h>
void main()
{
        int a,b;
        char n;
        clrscr();
printf(“enter the value of a and b=”);
        scanf(“%d%d”,&a,&b);
        printf(“enter the operation to perform=”);
        scanf(“%c”,&n);
            if(n==”+”)
        c=a+b;
        else if(n==”-“)
        c=a-b;
        else if(n==”*”)
        c=a*b;
            else if(n==”/”)
        c=a/b;
else if(n==”%”)
c=a%b;
printf(“the A %c B=%d”,n,c);
getch();
}

Comments