Input two numbers from users and a choice among the following numbers.
1->Add two numbers
2->Subtract two numbers
3->multiply two numbers
4->divide two numbers
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n1,n2,ch,r,d;
clrscr ( );
printf ("\n Enter two numbers..:"); scanf ("%d%d",&n1,&n2);
printf ("\n Press 1 to add.");
printf ("\n Press 2 to subtract.");
printf ("\n Press 3 to multiply.");
printf ("\n Press 4 to divide.");
printf ("\n Enter the choice..:");
scanf ("%d",&ch);
switch ( ch )
{
case 1:
r = n1 + n2;
printf ("\n Result of addition %d",r);
break;
case 2:
r = n1- n2;
printf ("\n Result of subtraction %d",r);
break;
case 3:
r = n1 * n2;
printf ("\n Result of multiplication %d",r);
break;
case 4:
r = n1 / n2;
d = n1 % n2;
printf ("\n Result of divition:\n Quotient=%d\tRemainder=%d",r,d);
break;
default:
printf("\n Invalid choice.");
}
getch();
}
Click here to contact us
No comments:
Post a Comment