Program demonstrating Basic arithmetic with the help of if-elseif ladder
#include <stdio.h>
#include <conio.h>
void main()
{
int x;
int y;
int r;
int choice;
clrscr();
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n\n\t\t.Enter Your Choice : ");
scanf("%d",&choice);
if( choice == 1)
{
printf("\nEnter X : ");
scanf("%d",&x);
printf("\nEnter Y : ");
scanf("%d",&y);
r = x + y;
printf("\nSum : %d",r);
}
else if( choice == 2)
{
printf("\nEnter X : ");
scanf("%d",&x);
printf("\nEnter Y : ");
scanf("%d",&y);
r = x - y;
printf("\nSub : %d",r);
}
else if( choice == 3)
{
printf("\nEnter X : ");
scanf("%d",&x);
printf("\nEnter Y : ");
scanf("%d",&y);
r = x * y;
printf("\nSub : %d",r);
}
else
{
printf("\n\nInvalid Choice");
}
getch();
}
Output :
0 comments:
Post a Comment