C Program - Calculator using IF-Else Statement

PROGRAM :

#include<stdio.h>
int main()
{
int a,b,c,opt;
printf("Enter two number to calculate\n");
scanf("%d%d",&a,&b);
printf("\nEnter 1 for Addition\nEnter 2 for Subtraction\nEnter 3 for Multiplication\nEnter 4 for Division\n\n");
scanf("%d",&opt);
if(opt==1)
{
    c = a+b;
    printf("\nSum of %d and %d is %d\n",a,b,c);
}
else if(opt==2)
{
    c = a-b;
    printf("\nDifference between %d and %d is %d\n",a,b,c);
}
else if(opt==3)
{
    c = a*b;
    printf("\nMultiplication of %d by %d is %d\n",a,b,c);
}
else if(opt==4)
{
    c = a/b;
    printf("\nDivision of %d by %d is %d\n",a,b,c);
}
else
{
    printf("\nIn appropriate option\n");
}
}





OUTPUT :

Enter two number to calculate
3
2

Enter 1 for Addition
Enter 2 for Subtraction
Enter 3 for Multiplication
Enter 4 for Division

1

Sum of 3 and 2 is 5

Post a Comment

0 Comments