Advertisement
Istanvir389

Simple Calculator Using Function

Oct 23rd, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 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 s_root(int num1);
  8. int power(int num1);
  9. int main()
  10. {
  11.   float n1,n2,result ;
  12.   printf("Enter Two Numbers ::\n ");
  13.  
  14.   scanf("%f",&n1);
  15.   scanf("%f",&n2);
  16.   int option ;
  17.    printf("Enter 1 for Addition\nEnter 2 for subtraction \nEnter 3 for Multiplication\nEnter 4 for Division\nEnter 5 for square root \nEnter 6 for power\n");
  18.  
  19.   scanf("%d",&option);
  20.   switch(option)
  21.   {
  22.   case 1:
  23.     result=add(n1,n2);
  24.     printf(" Addition is %f\n ", result );
  25.     break ;
  26.   case 2 :
  27.     result=sub(n1,n2);
  28.     printf("Subtraction is %f\n",result);
  29.     break ;
  30.   case 3 :
  31.  
  32.     result=multiple(n1,n2);
  33.     printf("Multiplication is %f\n",result);
  34.     break ;
  35.      case 4 :
  36.     result=division(n1,n2);
  37.     printf("Division is %f",result);
  38.     break ;
  39.  
  40.      case 5 :
  41.           result=s_root(n1);
  42.     printf("Square root is %f",result);
  43.  
  44.     break ;
  45.  case 6 :
  46.           result=power(n1);
  47.     printf("Power  is %f",result);
  48.  
  49.     break ; }
  50. }
  51.  
  52.     float add(float num1, float num2)
  53.     {
  54.         return num1+num2;
  55.     }
  56. float sub(float num1, float num2)
  57. {
  58.     return num1-num2;
  59.  
  60. }
  61. float multiple(float num1, float num2)
  62. {
  63.     return num1*num2;
  64. }
  65. float division(float num1, float num2)
  66. {
  67.     return num1/num2;
  68. }
  69. int s_root(int num1)
  70. {
  71.     return sqrt(num1);
  72. }
  73. int power(int num1)
  74. {
  75.     return pow(num1,2);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement