Not sure whats wrong with my program.

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 .

Example of what the output should be:

Enter·two·integers:45·5↵
·45·is·a·multiple·of·5↵
Enter·two·integers:59·8↵
·59·is·not·a·multiple·of·8↵
Enter·two·integers:12·54↵
·12·is·not·a·multiple·of·54↵
Enter·two·integers:890·119↵
·890·is·not·a·multiple·of·119↵
Enter·two·integers:126·2↵
·126·is·a·multiple·of·2↵
Enter·two·integers:27·4↵
·27·is·not·a·multiple·of·4↵


My Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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);
	else 
		return printf("%d is not a multiple of %d",a,b);
	
}
Last edited on
And what's the problem? How can we help you, if you don't tell us what the problem is?
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.

Hope this helps.
Topic archived. No new replies allowed.