#include
#include
int main(int argc, char *argv[]){
if(argc != 2) {
printf("pass one integer as an argument.\n");
exit(1);
}
if(atoi(argv[1]) % 2){
printf("That is an odd number\n");
}else{
printf("That is an even number\n");
}
return 0;
}
Chat with our AI personalities
CLS
PRINT "PROGRAM: Find if number is odd/or, even"
INPUT "Enter number: ", number$
number% = VAL(number$)
PRINT "The number is ";
IF number% MOD 2 = 0 THEN
PRINT "even."
ELSE
PRINT "odd."
END IF
END
In twos-complement notation, if the least-significant bit is set, then the number is odd, otherwise its even.
In ones-complement notation, positive values follow the convention of twos-complement values while negative values use the opposing convention, if the least-significant bit is set then the number is even, otherwise it is odd.
A slower method but one that is common to both ones-complement and twos-complement is to use the modus of the value. The modus of a value is the remainder after dividing by another value. If the other value is 2 then the modus can only be 0 (even) or 1 (odd).
In Java:
if (myNumber % 2 == 0)
System.out.println("The number is even.");
else
System.out.println("The number is odd.");
Similar in C or C++. The % operator is also used to check the remainder of a division, but you would have to change the output command.
Get number
Divide number by 2 and store remainder
if remainder equal 0 print "Even"
if remainder equal 1 print "odd"
end program
Number = Val(Textbox1.text)
If Number Mod 2 = 0 then
MsgBox("It is even.")
End If
If Number Mod 2 <> 0 then
MsgBox("It is odd.")
End If
void main()
{
int n;
printf("enter number :- ");
scanf("%d",&n);
(n%2==0)?"number is even" : "number is odd ";
getch();
}
first we write start and then read number and after that check the number is totaly divide by 2 or not if number is totally divide by 2 then number is even else number is odd.
To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.
printf(\n "ENTER THE NUMBER\t"); scanf{"%d",&a); while(a!=0); { r=a%2; if(r==0) printf("\n\n THE NUMBER IS EVEN \t"); else printf("\n\n THE NUMBER IS ODD \t"); printf ("\n ENTER THE NUMBER \t"); scanf("%d",&a); } getch(); }
echo "Program to check even or odd number"echo "Enter a number"read na=`expr $n % 2`if [ $a -eq 0 ] ; then #Semicolon is most important for Executing ifelse statementsecho "It is an even number"elseecho "It is an odd number"fi
It should not be even (except for 2), and must not be dividable with any odd number between 3 and its square-root.