c program
c program to check number is even or odd
Examples :-
// even or odd program if else
//if else statement statement only allows
// program to execute one block of code if a check condition
// is true than execute the block or condition is false than exite the block
// of code.
#include<stdio.h>
int main()
{
int number= 0;
printf("enter a number");
scanf("%d",&number);
if(number %2 ==0 )
{
printf("%d is even");
}
else
{
printf("%d is odd");
}
return 0;
}
c program to check number is even or odd use if else
Explain Program
Step :1
#include <stdio.h>
input-output use printf() & scanf() function.
Step :2
int main()
point of the C program. All execution .
Step :3
- printf("enter a number");
-
Prints a prompt for the user. You could add a newline ("\n") for cleanliness.
Step :4
- scanf("%d", &number);
-
Reads an integer from the user and stores it in number. The & gives the variable’s memory address.
Step :5
if (number % 2 == 0) {
printf("%d is even");
} else {
printf("%d is odd");
Step :6
- If (number % 2) == 0, there's no remainder, so it's even.
- Otherwise, it's odd.
Step :7
if (number & 1) // true if odd
(LSB is 1)
else // even (LSB is 0)
Step :8
printf("%d is even\n", number);
Add a newline to output for readability
No comments:
Post a Comment