Monday, October 3, 2011

Arithmatic operation using Switch case

Write a program to perform addition, subtraction, multiplication, division by reading arithmetic operators using Switch case.....



Program:


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char ch;
clrscr();
printf("Enter two numbers for arithmetic operation:\n");
scanf("%d%d",&a,&b);
printf("Enter the arithmetic operator (+,-,*,/)");
ch=getch();
switch(ch)
{
case '+':printf("\nSum=%d",a+b);
break;
case '-':printf("\ndiff=%d",a-b);
break;
case '*':printf("\nproduct=%d",a*b);
break;
case '/':printf("\nquotient=%d",a/b);
break;
default:printf("\nInvalid choice");
}
getch();
}

Sample Output:



0 comments:

Post a Comment

About Me