# What should I do?

This is a discussion on What should I do? within the C Programming forums, part of the General Programming Boards category; Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the ...

1. ## What should I do?

Write a function multiple 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.

2. And which part of your task is it you are struggling with?

How to mathematically determine if integer A is a multiple of integer B?
How to write a function in general, or something else?

--
Mats

3. Well technically all of it. lol But the main part that Im strugglin with is the math. Like what math do i need to do in order to return it true and to return it false.

4. So, what do you do if I say "Is 111 a multiple of 3" - you have pen and paper at hand.

--
Mats

5. Originally Posted by matsp
So, what do you do if I say "Is 111 a multiple of 3" - you have pen and paper at hand.

--
Mats
Well, 1 + 1 + 1 = 3. So of course 111 is a multiple of 3.

Or is it? dun, dun dun...

Perhaps a bigger hint than matsp's,
7 / 2 = 3 remainder 1
6 / 2 = 3 remainder 0

6. Originally Posted by zacs7
Well, 1 + 1 + 1 = 3. So of course 111 is a multiple of 3.

Or is it, dun, dun dun...
That is of course one way. That only works for 3 tho', so if I ask if 111 is a multiple of, say, 7, you can't use that method.

--
Mats

7. Yes it is. So as long as the the digits add up to be a multiple of 3 then its a multiple of 3? Is that right?

8. Originally Posted by jturner38
Yes it is. So as long as the the digits add up to be a multiple of 3 then its a multiple of 3? Is that right?
Yes, 3 is a "magical" number this way:
21 for example, or 63, or 18 are all multiples of three, and the sum of the numbers is a multiple of three. But it doesn't work for any other "A is multple of B", e.g. 25 does not make a sum of it's numbers that make 5 - but it is a multiple of 5.

So you need to work out something that works for ALL numbers.

--
Mats

9. Ok I know Im a need a loop to repeat that process. So a if statement should be fine. The only problem is how can i say this without setting anything to a specific value. Or will I have to? For instance how can I say the first integer is a multiple of the second or vice versa without specifying a value?

10. There is a very simple way to check if a value is a multiple of another value, yes, no matter what the different values are.

--
Mats

11. use % operator

if largeno%smallno is 0 then its divisible so its a multiple

12. Ok well in the second function after my main function. Would i use a for loop. How would u put it? I have it like this:

Code:
```     for(x % y)
if(remainder==0)
return 1(true)
if(remainder==1)
return 0(false)```

13. Originally Posted by jturner38
Ok well in the second function after my main function. Would i use a for loop. How would u put it? I have it like this:
Stop. The first part of your requirements asks you to do this: "Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the first."

I want to see your code for this function first. I also want to see you write the main function such that it calls this function with the values 10 and 5 as arguments, and based on the result prints whether 10 is a multiple of 5.

If you cannot get the above right, there is no point going further. At a glance, you need to grasp some basic syntax first, otherwise you are going to end up with a program that so badly needs to be fixed that you might as well give up and rewrite it from scratch.

14. I have this so far and i have only 3 errors!

Code:
```#include <stdio.h>

int multiple;

int main() {

int x;
int y;
int a;
int m;

printf("Enter first integer here:");
scanf("%d", x);

printf("Enter second integer here:");
scanf("%d", y);

m = int multiple(a)

return 0;
}

int multiple {
int a;

a = x % y;

if(a==0)
printf("The second integer is a multiple of the first");
return 1;
if(a==1)
printf("The second integer is not a multiple of the first");
return 0;```

15. Originally Posted by jturner38

int multiple;
this is variable definition
you want function declaration:

int multiply(int x, int y);

scanf("%d", x);
should be

scanf("%d", &x);

m = int multiple(a)
should be
m = multiply(x,y);

and do not forget tp print value of m afterwards

Code:
```int multiple {
int a;

a = x % y;

if(a==0)
printf("The second integer is a multiple of the first");
return 1;
if(a==1)
printf("The second integer is not a multiple of the first");
return 0;```
should start as
Code:
`int multiply(int x, int y) {`
if(a == 1) should be removed - a could be any value from 1 to y-1

also 2 statements after if(a ==0) should be placed inside
Code:
`{}`

Page 1 of 2 12 Last