-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp-3-3.c
More file actions
33 lines (27 loc) · 723 Bytes
/
exp-3-3.c
File metadata and controls
33 lines (27 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*************************************************************************
> File Name: exp-3-3.c
> Author: xiaoxiaoh
> Mail: xiaoxxhao@gmail.com
> Created Time: Fri Jun 30 09:10:30 2017
************************************************************************/
/*
* Write a C program to check whether a number is even or odd using conditional/ternary operator.
*
* Example:
*
* Input number: 10
*
* Output: Even number
*
*/
#include <stdio.h>
int main()
{
int num;
//read a number from user
printf("Enter a number: ");
scanf("%d", &num);
//(num % 2 == 0)? printf("%d is even\n", num): printf("%d is odd\n", num);
printf("%d is %s\n", num, (num%2 == 0? "even" : "odd"));
return 0;
}