Tuesday, June 16, 2009

Write a 'C' program to perform the selected arithmetic operation by taking two integer values using Switch Statement

#include(stdio.h)
#include(conio.h)
int main( )
{
int x,y;
char ch;
clrscr( );
printf("Enter the two integer values:);
scanf("%d%d",&x,&y);
printf("\nEnter the required arithmetic operator(+,-,*,/):");
fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case '+' : printf("\nAddition: %d", x+y); break;
case '-' : printf("\nSubstraction : %d", x-y); break;
case '*' : printf("\nMultiplication ; %d', x*y); break;
case '/': printf("\nDivision: %d", x/y); break;
default: printf("\nInvalid Arithmetic operator.");
}
getch( );
return 0;
}
Output:- Enter the two integer values: 30
20
Enter the required arithmetic operator(+,-,*,/): +
Addition: 50

No comments:

Post a Comment