+ 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?
3 Antworten
+ 9
Run this and check
https://code.sololearn.com/cibQ8d3KLZ40/?ref=app
+ 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
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);
}