+ 2
How To find the given no is odd or even using point to structure
C language
4 Respuestas
+ 1
#include <stdio.h>
struct evenOdd{
int n;
};
int main()
{
struct evenOdd *num, nums;
num = &nums;
printf("Enter the number: \t");
scanf("%d", &num->n);
if(num->n % 2 == 0){
printf("even");
}
else{
printf("odd");
}
return 0;
}
+ 2
Thank you
+ 2
@Brett Dahmer thanks for answer
+ 1
You could look at the numbers binary form using the & operator instead of performing a modulus operation (which takes more time)
//below looks at the least significant bit or the bit on the far right if it is a 1 then it is always odd, if 0 then it is even.
if(num->n & 1)
{
printf("odd");
}
else
printf("even");
return 0;