I cant figure the problem out!
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.
I dont know what I need to do to fix this!
Code:
#include <stdio.h>
int multiple(int x, int y, int a);
int main() {
int x;
int y;
int m;
int a;
printf("Enter first integer here:");
scanf("%d", &x);
printf("Enter second integer here:");
scanf("%d", &y);
m = multiple(x,y,a);
printf("%d is a multiple of the %d\n", m, m);
return 0;
}
int multiple(int x, int y, int a) {
a = x % y;
if(a == 0){
printf("%d is a multiple of the %d\n", y, x);
return 1;
else(a != 0);
printf("%d is not a multiple of the %d\n", y, x);
return 0;
}
}
Replace else ---> else if
Quote:
Originally Posted by
peeweearies
You want to find if the second number is a multiple of the first number....then you have to check your multiple(int x, int y) function on your return statement. It's backward. That's not the only thing that is backwards, look at the variables on your printf statements within your if/else statements.
There are couple of mistakes in your code:-
1. Don't use condition for both if and else
if you want check multiple condition better to use if and else if combination.
2. you trying to display the result in both main and subfunction.
i don't see any usage of such kind of code.
better you can display result either in main or subfunction.