The Program in C to find out how many of them are positive, how many are negative , how many are even and how many are odd when user puts it into is given below:
#include <stdio.h>
int main() {
int num, i, pos_count = 0, neg_count = 0, even_count = 0, odd_count = 0;
printf("Enter the numbers (Enter -1 to stop): \n");
for (i = 0; ; i++) {
scanf("%d", &num);
if (num == -1) {
break;
}
if (num > 0) {
pos_count++;
} else if (num < 0) {
neg_count++;
}
if (num % 2 == 0) {
even_count++;
} else {
odd_count++;
}
}
printf("Positive numbers: %d\n", pos_count);
printf("Negative numbers: %d\n", neg_count);
printf("Even numbers: %d\n", even_count);
printf("Odd numbers: %d\n", odd_count);
return 0;
}
Output:
Enter the numbers (Enter -1 to stop):
2
10
19
14
15
-3
-5
-1
Positive numbers: 5
Negative numbers: 2
Even numbers: 3
Odd numbers: 4
Pro-Tips💡
This program uses a for loop to repeatedly read in numbers from the user until -1 is entered.
It uses if else statements to check if the numbers are positive, negative, even or odd and keeps a count of each case.
Finally, it prints out the counts of each category.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.