Program to determine if a number is even or odd in C – Programming and Electronics

Program to determine if a number is even or odd in C

In this example, we will show a program that asks for a number, then the program will tell us if the number is even or odd, the code is;

#include <stdio.h>
main ()
{
int n;
printf (“Enter a number”);
scanf (“% d”, & n);
if (n% 2 == 0)
{
printf (“% d is even”, n);
}
else
{
printf (“% d is odd”, n);
}
getchar ();
getchar ();
return 0;
}
In this code we declare a variable of type integer called n, a number is requested, and then, through an if cycle, it is analyzed if the module of that number is zero, if so, the program will say that the number is even, otherwise, it will say that it is odd.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!