Advertisement
opurag

1.Write a program to add, subtract, multiply and divide two integers using user defined type functio

Oct 10th, 2022
1,463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. //1.Write a program to add, subtract, multiply and divide two integers using user defined type function with return type.//
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7. int add(int a, int b);
  8. int sub(int a, int b);
  9. int mul(int a, int b);
  10. int div(int a, int b);
  11.  
  12. void main()
  13. {
  14.  int x,y,op;
  15.  
  16.  printf("Enter two integers \n");
  17.  scanf("%d %d",&x,&y);
  18.  
  19.  printf("Enter the operation to be execute \n Choose: \n 1 for addition \n 2 for subtraction \n 3 for multiplication \n 4 for division \n");
  20.  scanf("%d",&op);
  21.  
  22.  switch(op)
  23.  {
  24.   case 1:
  25.   printf("The sum is %d \n",add(x,y));
  26.   break;
  27.  
  28.   case 2:
  29.   printf("The difference is %d \n",sub(x,y));
  30.   break;
  31.  
  32.   case 3:
  33.   printf("The product is %d \n",mul(x,y));
  34.   break;
  35.  
  36.   case 4:
  37.   printf("%d divided by %d = %d \n",x,y,div(x,y));
  38.   break;
  39.  
  40.   default:
  41.   printf("Error");
  42.   break;
  43.   }
  44.  
  45.  }
  46.  
  47.  int add(int a, int b)
  48.  {
  49.   return (a+b);
  50.  }
  51.  
  52.  int sub(int a, int b)
  53.  {
  54.   return (a-b);
  55.  }
  56.  
  57.  int mul(int a, int b)
  58.  {
  59.   return(a*b);
  60.  }
  61.  
  62.  int div(int a,int b)
  63.  {
  64.   return(a/b);
  65.  }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement