Write a program that defines and uses the following five fun

Write a program that defines and uses the following five functions: int Addlnt(int Opl, int Op2); int Sublnt(int Opl, int Op2); int MulInt(int Opl, int Op2); int Divlnt(int Opl, int 0p2); int Kodlnt(int Opl, int Op2); Divlnt () and Modint () should contain code to check if0p2 is equal to zero (which would lead to a division by zero). If Op2 is equal to zero, do not perform the operation but instead print the following error messages (as appropriate) and return a value of zero. Error - Divlnt() 0p2 is 0. No division performed, 0 returned. Error - Modlnt() Op2 is 0. No modulus performed, 0 returned. Call each function four times with a variety of valid operands and print out the results in the format: AddInt(, ) = Do not print the strings , , and . These should be decimal numbers that were the arguments to and the return value from calling the function. Since there are five functions, your program should produce twenty lines of output. Be sure to call each function one time with Op2 set to zero, to test the error checking in DivInt() and Modint().

Solution

#include <stdio.h>

int AddInt(int Op1,int Op2) //Adding two operands
{
   return (Op1+Op2);
}

int SubInt(int Op1,int Op2) //subtracting two operands
{
   return (Op1-Op2);
}

int MulInt(int Op1,int Op2) //multiplying two operands
{
   return (Op1*Op2);
}

int DivInt(int Op1,int Op2) //dividing two operands
{
   if(Op2==0) //check for denominator=0
   {
   printf(\"\ Error - DivInt() Op2 is 0. No Division performed . 0 returned\");
   return 0;
   }
   return (Op1/Op2);
}

int ModInt(int Op1,int Op2) //computing remainder
{
   if(Op2==0) //check for denominator=0
   {
   printf(\"\ Error - ModInt() Op2 is 0. No Modulus performed . 0 returned\");
   return 0;
   }
   return (Op1%Op2);
}

int main(void)
{
   printf(\"\ AddInt(34,56)=%d\",AddInt(34,56));
   printf(\"\ AddInt(45,89)=%d\",AddInt(45,89));
   printf(\"\ AddInt(33,0)=%d\",AddInt(33,0));
   printf(\"\ AddInt(0,78)=%d\",AddInt(0,78));
  
   printf(\"\ \ SubInt(34,56)=%d\",SubInt(34,56));
   printf(\"\ SubInt(45,89)=%d\",SubInt(45,89));
   printf(\"\ SubInt(33,0)=%d\",SubInt(33,0));
   printf(\"\ SubInt(0,78)=%d\",SubInt(0,78));
  
   printf(\"\ \ MulInt(34,56)=%d\",MulInt(34,56));
   printf(\"\ MulInt(45,89)=%d\",MulInt(45,89));
   printf(\"\ MulInt(33,0)=%d\",MulInt(33,0));
   printf(\"\ MulInt(0,78)=%d\",MulInt(0,78));
  
   printf(\"\ \ DivInt(200,34)=%d\",DivInt(200,34));
   printf(\"\ DivInt(45,12)=%d\",DivInt(45,12));
   printf(\"\ DivInt(33,0)=%d\",DivInt(33,0));
   printf(\"\ DivInt(0,78)=%d\",DivInt(0,78));
  
   printf(\"\ \ ModInt(200,34)=%d\",ModInt(34,56));
   printf(\"\ ModAdd(45,12)=%d\",ModInt(45,12));
   printf(\"\ ModInt(33,0)=%d\",ModInt(33,0));
   printf(\"\ ModInt(0,78)=%d\",ModInt(0,78));
  
   return 0;
}

Output:

Success time: 0 memory: 2168 signal:0

 Write a program that defines and uses the following five functions: int Addlnt(int Opl, int Op2); int Sublnt(int Opl, int Op2); int MulInt(int Opl, int Op2); i
 Write a program that defines and uses the following five functions: int Addlnt(int Opl, int Op2); int Sublnt(int Opl, int Op2); int MulInt(int Opl, int Op2); i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site