Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.Write a program to add, subtract, multiply and divide two integers using user defined type function with return type.//
- #include <stdio.h>
- int add(int a, int b);
- int sub(int a, int b);
- int mul(int a, int b);
- int div(int a, int b);
- void main()
- {
- int x,y,op;
- printf("Enter two integers \n");
- scanf("%d %d",&x,&y);
- 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");
- scanf("%d",&op);
- switch(op)
- {
- case 1:
- printf("The sum is %d \n",add(x,y));
- break;
- case 2:
- printf("The difference is %d \n",sub(x,y));
- break;
- case 3:
- printf("The product is %d \n",mul(x,y));
- break;
- case 4:
- printf("%d divided by %d = %d \n",x,y,div(x,y));
- break;
- default:
- printf("Error");
- break;
- }
- }
- int add(int a, int b)
- {
- return (a+b);
- }
- int sub(int a, int b)
- {
- return (a-b);
- }
- int mul(int a, int b)
- {
- return(a*b);
- }
- int div(int a,int b)
- {
- return(a/b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement