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

Program Code

Uploaded by

reshma
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 views

Program Code

Uploaded by

reshma
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/ 2

include<stdio.

h>
int main()
{
int a,b,result=0;
char op;
printf("Enter the operator\n");
scanf("%c",&op);
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
if(op=='+')
{
result=a+b;
}
else if(op=='-')
{
result=a-b;
}
else if(op=='*')
{
result=a*b;
}
else if(op=='/')
{
if(b==0)
{
printf("divide by zero error\n");
return 1;
}
else
{
result=a/b;
}
}

else if(op=='%')
{
if(b==0)
{
printf("divide by zero error\n");
return 1;
}
else
{
result=a%b;
}
}
else
{
printf("invalid operator\n");
return 1;
}
printf("Result is %d%c%d=%d",a,op,b,result);
return 0;
}

SAMPLE OUTPUT:

QUESTIONS FOR VIVA:


1. Why do we need to include a stdio.h file in a C program?
2. What is an operator in C?
3. What are the different types of arithmetic operators?

Department of Computer Science &amp; Engineering, CMRIT, Bangalore

4. What are the different types of relational operators?


5. What is the difference between / and % operator?
6. Why do we use printf()?
7. Why do we use scanf()?
8. Explain looping structures in C.
9. Explain decision control structures in C.

You might also like