// Consider the operators +, -, *, / and use switch statement.
#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int main(void)
{
int x, y;
char ch;
clrscr( );
printf("Enter the two integer values:");
scanf("%d %d",&x, &y);
printf("\nEnter the required operator( +, -, *, / ): ");
fflush(stdin); //to flush [clear] the input buffer.
scanf("%c", &ch);
switch(ch)
{
case '+' : printf("\n Addition : %d", x+y); break;
case '-' : printf("\n Substraction : %d", x-y); break;
case '*' : printf("\n Multipliaction : %d", x*y); break;
case '/': printf("\n Division: %d", x/y); break;
default: printf("\nInvalid operator, please check once again.");
}
getch();
return 0;
}
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Tuesday, January 6, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment