## Search Your Topic

Friday, 15 September 2017 08:54

## C- if else Program

Written by
Rate this item

### C-Program to Check Even or Odd

``````#include <stdio.h>
int main()
{
int number;

printf("Enter an integer: ");
scanf("%d", &number);

// True if the number is perfectly divisible by 2
if(number % 2 == 0)
printf("%d is even.", number);
else
printf("%d is odd.", number);

return 0;
}``````

Output

```Enter an integer: -7
-7 is odd.```

## C-Program to Check Odd or Even Using Conditional Operator

``````#include <stdio.h>
int main()
{
int number;

printf("Enter an integer: ");
scanf("%d", &number);

(number % 2 == 0) ? printf("%d is even.", number) : printf("%d is odd.", number);

return 0;
}``````
` `

### `// If user enters positive number, that number won't be displayed`

``````#include <stdio.h>
int main()
{
int number;

printf("Enter an integer: ");
scanf("%d", &number);

// Test expression is true if number is less than 0
if (number < 0)
{
printf("You entered %d.\n", number);
}

printf("The if statement is easy.");

return 0;
}``````

Output 1

```Enter an integer: -2
You entered -2.
The if statement is easy.```

When user enters -2, the test expression `(number < 0)` becomes true. Hence, You entered -2 is displayed on the screen.

Output 2

```Enter an integer: 5
The if statement in C programming is easy.```

Read 5409 times Last modified on Friday, 15 September 2017 09:04

### Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

Call +91 74 88 34 7779  | Email : anishsingh@live.com