fork download
  1. #include<stdio.h>
  2. void main()
  3. {
  4. float sum,sub,mul,div,a,b;
  5. int choice,mod;
  6. printf("Enter the values of a and b\n");
  7. scanf("%f%f",&a,&b);
  8. printf("Enter 1 for addition\n2 for subtraction\n3 for multiplication\n4 for division\n5 for modulus\n");
  9. scanf("%d%d",&choice,&mod);
  10. switch(choice)
  11. {
  12. case 1:printf("Addition");
  13. sum=a+b;
  14. printf("%f",sum);
  15. break;
  16. case 2:printf("Subtraction");
  17. sub=a-b;
  18. printf("%f",sub);
  19. break;
  20. case 3:printf("Multiplication");
  21. mul=a*b;
  22. printf("%f",mul);
  23. break;
  24. case 4:printf("Division");
  25. if(b==0)
  26. {
  27. printf("Divide by zero error! please enter a non zero number.");
  28. }
  29. else
  30. {
  31. div=a/b;
  32. printf("%f",div);
  33. break;
  34. }
  35. case 5:printf("Modulus");
  36. if(a<b)
  37. mod=a;
  38. else
  39. mod=(int)a%(int)b;
  40. printf("%d",&mod);
  41. break;
  42. Default:printf("Wrong choice, enter correct choice");
  43. }
  44. }
Success #stdin #stdout 0s 5284KB
stdin
fwp
stdout
Enter the values of a and b
Enter 1 for addition
2 for subtraction
3 for multiplication
4 for division
5 for modulus