0

# How to separate odd,even and prime using functions without return type and with parameter in c?

2 Answers

+ 2

C#
public static bool chkOdd(int num)
{
if (num %2 == 1) return true; else return false;
}
public static bool chkEven(int num)
{
if (num %2 == 0) return true; else return false;
}
public static bool chkPrime(int num)
{
for (int i=2; i<num; i++) if (num %i == 0) return false;
return true;
}
https://code.sololearn.com/cJqJ46Lalczq

+ 2

C
int n;
scanf("%d",&n);
if (n %2 == 1)
printf("%d %s\n", n, "is an odd number");
else
printf("%d %s\n", n, "is not an odd number");
if (n %2 == 0)
printf("%d %s\n", n, "is an even number");
else
printf("%d %s\n", n, "is not an even number");
int p=1;
for (int i=2; i<n; i++) if (n %i == 0) {p=0; break;}
if (p==1)
printf("%d %s\n", n,"is a prime number");
else
printf("%d %s\n", n,"is not a prime number");
https://code.sololearn.com/cn7bc0Uk3evY