C LANGUAGE
Create your own library named cis340yourlastname.
Create a header file named cis340yourlastname.
Write a program that receives two numbers from the user and uses your written library to calculate the reminder after division, the addition, and the subtraction of these two input numbers. (Hint your library should include three functions. Your header file should not contain the code for any of these functions, it should contain only the instructions for how to use the library).
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
Make sure you copy below three files (header file, implementation file and test file) into separate files as mentioned. Do not copy everything to a single file.
//cis340yourlastname.h file (change file name as needed)
#ifndef cis340yourlastname_h //change this according to file name
#define cis340yourlastname_h //change this according to file name
//declarations for all three functions needed
//returns the remainder of a/b.
//example usage:
//rem(10,5) will return 0
//rem(5,2) will return 1
int rem(int a, int b);
//adds two integers and return the sum
//example usage:
//add(10,13) will return 23
int add(int a, int b);
//return the result of a-b
//example usage:
//sub(10,13) will return -3
int sub(int a, int b);
#endif
//end of cis340yourlastname.h file
//cis340yourlastname.c file
#include "cis340yourlastname.h"
//defining the body of each method declared in cis340yourlastname.h file
int rem(int a, int b){
return a % b;
}
int add(int a, int b){
return a + b;
}
int sub(int a, int b){
return a - b;
}
//end of cis340yourlastname.c file
//main.c for testing
#include<stdio.h>
#include "cis340yourlastname.h" //including cis340yourlastname header file
int main(){
int a,b;
//asking and reading values of two integers
printf("Enter two integers: ");
scanf("%d %d",&a,&b);
//displaying remainder, addition and subtraction results
printf("Remainder after division: %d\n",rem(a,b));
printf("Addition: %d\n",add(a,b));
printf("Subtraction: %d\n",sub(a,b));
return 0;
}
//end of main.c
/*OUTPUT*/
Enter two integers: 5 2
Remainder after division: 1
Addition: 7
Subtraction: 3
Get Answers For Free
Most questions answered within 1 hours.