+ 2

How to make a method that receives a number by parameter, and this tells me if it is divisible by: 2,3,5. or none of the above?

26th Dec 2017, 9:13 PM
Anthony
3 odpowiedzi
27th Dec 2017, 12:05 AM
Justine Ogaraku
Justine Ogaraku - avatar
+ 3
Not sure if this is what you mean, but if you pass the number and the divisor to this method it will return whether or not the number can be evenly divided by the divisor. boolean isDivisibleBy(int num, int divisor) { return num % divisor == 0; } isDivisibleBy(10, 2); // true isDivisibleBy(10, 3); // false
26th Dec 2017, 9:41 PM
ChaoticDawg
ChaoticDawg - avatar
0
int main() { void isdivisible(int); //function prototype int a; printf("enter a number"); scanf("%d",&a); isdivisible(a); return 0; } void isdivisible(int a) { if(a%2==0) { if(a%3==0) { if(a%5==0) printf("divisible by 2,3 and 5"); else printf("not divisible by 2,3 and 5); } else printf("not divisible by 2,3 and 5); } else printf("not divisible by 2,3 and 5); }
29th Dec 2017, 2:56 PM
manas palai