Saturday, 13 December 2014

C PROGRAM CALCULATOR (SWITCH STATEMENT)

Write a program to find the Multiplication, subtraction, addition and division of the numbers. (Switch statement)


#include<stdio.h>
#include<conio.h>
int main()
{
int choice;
float a, b, c;
clrscr();
printf("Enter the two numbers");
scanf("%f %f", &a, &b);
printf(" Press 1 for Addition:");
printf("\n Press 2 for Subtraction:");
printf("\n Press 3 for Product:");
printf("\n Press 4 for Division:");
scanf("%d",&choice);
switch(choice)
{
case 1:
     c=a+b;
     printf("The sum is:%f",c);
     break;
case 2:
     c=a-b;
     printf("The different is:%f",c);
     break;
case 3:
     c=a*b;
     printf("The Product is:%f",c);
     break;
case 4:
     c=a/b;
     printf("The Division is: %f",c);
     break;
default:
printf("Invalid Choice \n ");
}
getch();
return(0);
}

OUTPUT:
Enter the two numbers
4 4
Press 1 for Addition:
Press 2 for Subtractions:
Press 3 for Product
Press 4 for Division
1

The sum is: 8

No comments:

Post a Comment