# Thread: beginner multiple function

1. ## beginner multiple function

OT: Being a total beginner to programming but having lots of free time I recently started practicing. Having a rough time on functions. Thanks to everyone in advance.

THE PROBLEM:
Given 2 integers N and M from standard input, using a multiples function, calculate the integers in [1,N] multiple of M. Print the sets in increasing order.

MY (WRONG) SOLUTION:

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

int multipli(int,int);
int multipli (int x, int y)
{
int i;
for (i=1;i<=x;i++)
{
if((i%y)==0)
{
return i;
}
}
}
int main(void)
{
int N;
int M;
scanf("%d", &N);
scanf("%d", &M);
printf("%d", multipli(N,M));
return 0;
}```
Thanks again in advance.

2. Instead of returning a multiple, you could print it in the loop body.

You might also consider if skipping numbers by the multiple might be a more efficient approach.

3. I'm still getting "output isn't correct" (practicing on an autoevaluator platform) after trying both suggestions.
I really thought the mistake was inthe printf command.
Maybe I'll just skip this one.
But your suggestions are great, I should start thinking about efficiency more.

4. > I'm still getting "output isn't correct" (practicing on an autoevaluator platform) after trying both suggestions.
You need to be very specific about what format the auto checker expects.

For example, not printing newlines would be a killer if you print
5101520
and not as expected
5
10
15
20

5. OMG, thanks, that's it! I forgot to notice the commas dividing the numbers in the output. Sorry for making you waste your time on something like this, I hope to be able to give back sooner or later.

Popular pages Recent additions