Md_hosen_zisad

make a calculator by function

Oct 23rd, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. float add(float num1,float num2);
  4. float sub(float num1,float num2);
  5. float multiple(float num1,float num2);
  6. float division(float num1,float num2);
  7. int power(int num1);
  8.  
  9. int main()
  10. {
  11. float n1,n2,result;
  12. scanf("%f %f",&n1,&n2);
  13. int option;
  14. scanf("%d",&option);
  15. switch(option)
  16. {
  17. case 1:
  18. result=add(n1,n2);
  19. printf("%f",result);
  20. break;
  21. case 2:
  22. result=sub(n1,n2);
  23. printf("%f",result);
  24. break;
  25. case 3:
  26. result=multiple(n1,n2);
  27. printf("%f",result);
  28. break;
  29. case 4:
  30. result=division(n1,n2);
  31. printf("%f",result);
  32. break;
  33. case 5:
  34. result=power(n1);
  35. printf("%f",result);
  36. break;
  37. }}
  38. float add(float num1,float num2)
  39. {
  40. return num1+num2;
  41.  
  42. }
  43. float sub(float num1,float num2)
  44. {
  45. return num1-num2;
  46.  
  47. }
  48. float multiple(float num1,float num2)
  49. {
  50. return num1*num2;
  51.  
  52. }
  53.  
  54. float division(float num1,float num2)
  55. {
  56. return num1/num2;
  57.  
  58. }
  59.  
  60. int power(int num1)
  61. {
  62. return pow(num1,2);
  63.  
  64. }
Add Comment
Please, Sign In to add comment