write a program to check whether a int type number is taken as input is positive, negative or zero
Answers
Answered by
2
Answer:
We can Code this in two ways:-
C Language:-
- If....else:-
#include <stdio.h>
int main() {
double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");} else
printf("You entered a positive number.");
return 0;}
- Nested if
#include <stdio.h>
int main() {
double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");
} else
printf("You entered a positive number.");
return 0;}
Similar questions
Social Sciences,
2 months ago
Math,
4 months ago
Math,
10 months ago
English,
10 months ago
Physics,
10 months ago