Write a Program to perform arithmetical calculation using if else if statement.

 Write a Program to perform arithmetical calculation using if else if statement.

#include<stdio.h>

#include<conio.h>

void main()

{

float num1,num2,res;

int choice;

clrscr();

printf("\n\t*************************************************************");

printf("\n\t***************** Malhotra Computer Centre ******************");

printf("\n\t*************************************************************");

printf("\n\n\t------------------------- Menu ----------------------------");

printf("\n\t\tProgram to perform Arithmetical Operation :");

printf("\n\n\tPress 1 for Addition :" );

printf("\n\tPress 2 for Subtraction : ");

printf("\n\tPress 3 for Multiplication :");

printf("\n\tPress 4 for Division : ");

printf("\n\t-------------------------------------------------------------");

printf("\n\tInput your choice :\t");

scanf("%d",&choice);

if(choice==1)

{

printf("\n\tInput any number : ");

scanf("%f",&num1);

printf("\n\tInput any number : ");

scanf("%f",&num2);

res=num1+num2;

printf("\n\tThe Result is : %0.2f",res);

}

else if(choice==2)

{

printf("\n\tInput any number : ");

scanf("%f",&num1);

printf("\n\tInput any number : ");

scanf("%f",&num2);

res=num1-num2;

printf("\n\tThe Result is : %0.2f",res);

}

else if(choice==3)

{

printf("\n\tInput any number : ");

scanf("%f",&num1);

printf("\n\tInput any number : ");

scanf("%f",&num2);

res=num1*num2;

printf("\n\tThe Result is : %0.2f",res);

}

else if(choice==4)

{

printf("\n\tInput any number : ");

scanf("%f",&num1);

printf("\n\tInput any number : ");

scanf("%f",&num2);

res=num1/num2;

printf("\n\tThe Result is : %0.2f",res);

}

else

{

printf("\n\tInvalid choice!!!");

printf("\n\tPlease read the instruction carefully and input a Valid choice");

}

getch();

}

Comments