luc031.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 12 Dec 2025
- License — MIT
Problem Statement ​
Problem Statement
Write a program to enter numbers till the user wants. At the end it should display the count of positive, negative and zeros entered.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
int main()
{
int choice = 1, num, positive_count = 0, negative_count = 0, zero_count = 0;
while (choice == 1)
{
printf("\nEnter the number (Type any character and press Enter to finish.) : ");
choice = scanf("%d", &num); // Checking whether the user has input any characters
if (choice == 1)
{
printf("Number recorded : %d", num);
if (num < 0)
negative_count++;
else if (num > 0)
positive_count++;
else if (num == 0)
zero_count++;
}
else
{
// If the user inputs any characters, then choice = 0, it means he doesn't want to give any more input;
choice = 0;
printf("\nCharacter received. Stopping input...\n");
}
}
// Display the final results
printf("\n====================================\n");
printf(" Analysis Complete\n");
printf("====================================\n");
printf("Positive numbers entered: %d\n", positive_count);
printf("Negative numbers entered: %d\n", negative_count);
printf("Zeroes entered: %d\n", zero_count);
printf("Total numbers recorded: %d\n", positive_count + negative_count + zero_count);
printf("====================================\n");
}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
34
35
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
34
35