5.17 (Multiples) Write a function isMultiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true ) if the second is a multiple of the first, and 0 (false ) otherwise. Use this function in a program
that inputs a series of pairs of integers .
#include <stdio.h>
char remainderZeroOrNot(int a,int b);
int main(void) {
int a,b;
printf("Enter two integers: ");
scanf("%d %d",&a,&b);
remainderZeroOrNot(a,b);
}
char remainderZeroOrNot(int a,int b){
if (a%b==0)
return printf("%d is a multiple of %d",a,b);
elsereturn printf("%d is not a multiple of %d",a,b);
}
Your code is almost correct. But a few important details have been left out.
In the remainderZeroOrNot function definition the return type shouldn't be char, if you want the function to print out a string based on certain outcome in your implementation. So, the return type could be string, if you like or you simply make the return type void, then in the return printf("%d is not a multiple of %d",a,b); statement, change it to printf("%d is a multiple of %d",a,b);
or
printf("%d is not a multiple of %d",a,b);
as the case may be.
More so, if you prefer to use a return type of string, assign the string values "%d is not a multiple of %d" and "%d is a multiple of %d" to the string variables.
Use the method of a return type of void, it's simpler to understand.