Wednesday, February 18, 2015

C program to perform arithmetic operations using switch case


C program to perform arithmetic operations using switch case

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
int ch;
float a,b,res;
clrscr();
printf("Enter two numbers:");
scanf("%f%f",&a,&b);
printf("
Menu
1.Addition
2.Subtraction
3.Multiplication
4.Division");

printf("
Enter your choice:");

scanf("%d",&ch);

switch(ch)
{
case 1: res=a+b;
break;
case 2: res=a-b;
break;
case 3: res=a*b;
break;
case 4: res=a/b;
break;
default: printf("Wrong choice!!
Press any key...");

getch();
exit(0);
}

printf("
Result=%f",res);

getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.