C Program To Create Arthematic Operations In Switch Case

#include<stdio.h>
#include<conio.h>
void main()
{
 int opt,opt1,opt2,opt3,opt4,add,sub,mul,num1,num2;
 float div;
 clrscr();
 printf("enter num1,num2");
 scanf("%d%d",&num1,&num2);
 printf("\n 1.addition \n 2.subtraction \n 3.multiplication \n 4.division \n");
 scanf("%d",&opt);
 switch(opt);
 {
 switch(opt==1)
 {
  add=num1+num2;
  printf("addition is %d",add);
  break;
 }
 switch(opt==2)
 {
  sub=num1-num2;
  printf("subtraction is %d",sub);
  break;
 }
 switch(opt==3)
 {
  mul=num1*num2;
  printf("multiplication is %d",mul);
  break;
 }
 switch(opt==4)
 {
  div=num1/num2;
  printf("division is %f",div);
  break;
 }
 }
 getch();
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment