C Program For Arithmetic Calculator using if else ladder(2 operands 1 operator frm user)

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,opt;
l: printf("enter the following option");
printf("\n1.add\n2.asub\n3.mul\n4.exit");
scanf("%d",&opt);
if(opt==1)
{
printf("enter first operand");
scanf("%d",&a);
printf("enter second operand");
scanf("%d",&b);
printf("a+b=%d",a+b);
}
else if(opt==2)
{
printf("enter the 1operand");
scanf("%d",&a);
printf("enter 2nd operand");
scanf("%d",&b);
printf("a-b=%d",a-b);
}
else if(opt==3)
{
printf("enter the 1st value");
scanf("%d",&a);
printf("enter the 2nd value");
scanf("%d",&b);
printf("\n a*b=%d",a*b);
}
else if(opt==4)
exit(0);
else
printf("\nwrong option\n");
goto l;
getch();
}




Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

1 comment:

Unknown said...

good work bro but you put the longer way to do the programming

Post a Comment