C program to check a number is positive or not
Write a C program to check a number is positive or not.
Example:
Enter no: 2
Output: No is positive
Enter no: -5
Output: No is negative
Enjoy it.............
Enter no: 2
Output: No is positive
Enter no: -5
Output: No is negative
Required knowledge:
Fundamentals of C, Data types, Taking user input in C, IF-else
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
/*****************************************************
* C program to check a number is positive or not *
*****************************************************/
#include <stdio.h>
void main()
{
int
num;
/* Read number from user */
printf
(
"Enter any number: "
);
scanf
(
"%d"
, &num);
if
(num > 0)
{
printf
(
"Number %d is POSITIVE",num
);
}
else
if
(num < 0)
{
printf
(
"Number %d is NEGATIVE",num
);
}
else
{
printf
(
"Number %d is ZERO",num
);
}
}
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
| /***************************************************** * C program to check a number is positive or not * *****************************************************/ #include <stdio.h>
void
main() { int num; /* Read number from user */ printf ( "Enter any number: " );
scanf ( "%d" , &num); if (num > 0) { printf ( "Number %d is POSITIVE",num ); } else if (num < 0) { printf ( "Number %d is NEGATIVE",num ); } else { printf ( "Number %d is ZERO",num ); } } |
Enjoy it.............
Comments
Post a Comment
Dears! Yours Comment approved in 24 hours also your answer in 24 hours.......