Count of Positive, Negative, and Zero Numbers
This program counts the number of positive, negative, and zero numbers from a user-provided set of integers. It prompts the user to enter a specified number of integers and then classifies each integer into one of three categories: positive, negative, or zero. The program finally displays the counts of each category.
Code Breakdown
Algorithm
- Start
- Input Limit: Read the value of
n
(number of integers) from the user. - Initialize Counters:
- Set
pc
,nc
, andzc
to 0 for counting positives, negatives, and zeroes, respectively.
- Set
- Read Integers:
- Loop
n
times to read integers from the user. - For each integer
x
:- If
x
is positive, incrementpc
. - If
x
is negative, incrementnc
. - If
x
is zero, incrementzc
.
- If
- Loop
- Display Results:
- Print the counts of positive, negative, and zero numbers.
- End
Code Explanation
Example Flowchart
Start
|
V
Input limit n
|
V
Initialize pc, nc, zc to 0
|
V
For i = 0 to n-1
|
V
Read integer x
|
V
Is x > 0?
/ \
/ \
/ \
/ \
/ \
/ \
/ \
Yes No
/ \
/ \
V V
Increment pc Is x < 0?
| / \
| Yes No
| / \
| V V
| Increment nc Increment zc
V | |
| V V
| End End
|
V
End