Question :
A normal number is defined
to be one that has no odd factors, except for 1 and possibly itself. Write a
method named isNormal that returns 1 if its integer argument is normal,
otherwise it returns 0. The function signature is
int isNormal(int n)
Examples: 1, 2, 3, 4, 5, 7, 8 are normal numbers.
6 and 9 are not normal numbers since 3 is an odd factor. 10 is not a normal
number since 5 is an odd factor.
Solution :
public static int
isNormal(int n)
{
int result
= 1;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
if(i%2!=0)
{
result = 0;
break;
}
}
}
return result;
}
//This is my brief code
ReplyDeletestatic int isNormal(int n) {
for (int i = 2; i < n; i++) {
if (n % i == 0 && i % 2 != 0) {
return 0;
}
}
return 1;
}
}