Odd and Even
Welcome in C programming, in this tutorial we will be looking at how to write a program that asks a user to input an integer and the program determines if the integer is odd or even.
An even number is a number that can be divided into two equal groups. While an odd number is a number that cannot be divided into two equal groups.
We will be using the IF/ELSE statement to compare the variable imputed by the user, so if "num" which is the variable name that holds the user input divides two (2) with no reminder, then its an even number, else its an odd number.
The program below, shows the step on how these is achieved.
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num;
printf("Enter a number:");
scanf("%d", &num);
if(num%2==1){
printf("%d is an odd number\n", num);
}
else{
printf("This number %d is an Even number", num);
}
return 0;
}
Comments
Post a Comment
Please feel free to comments if you have any ideas, questions and subjection concerning our post and programs