0% found this document useful (0 votes)
286 views2 pages

C++ Programming CODE-Algorithm-Flowchart of Positive Negative Zero

The code segment initializes arrays to separate input numbers into positive, negative, and zero categories. It prompts the user to input 10 numbers, stores them in an array, and uses conditional statements to sort each number into the corresponding category array. Finally, it outputs the numbers in each category array separately.

Uploaded by

Marlon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views2 pages

C++ Programming CODE-Algorithm-Flowchart of Positive Negative Zero

The code segment initializes arrays to separate input numbers into positive, negative, and zero categories. It prompts the user to input 10 numbers, stores them in an array, and uses conditional statements to sort each number into the corresponding category array. Finally, it outputs the numbers in each category array separately.

Uploaded by

Marlon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CODE:

#include<iostream>
using namespace std;

int main()
{
int arr[10],positive[10],negative[10],zero[10],l=0,i=0,j=0,k=0;

for(i=0; i<=9;i++)
{
cout<<"Input a number: ";
cin>>arr[i];
}

for(i=0; i<=9;i++)
{
if(arr[i]==0)
{
zero[l]=arr[i];
l++;
}
else if(arr[i]>0)
{
positive[j]=arr[i];
j++;
}
else
{
negative[k]=arr[i];
k++;
}
}
cout<<"\nZero: ";
for(i=0; i<l; i++)
{
cout<<zero[i]<<" ";
}
cout<<"\nPositive numbers: ";
for(i=0; i<j ;i++)
{
cout<<positive[i]<<" ";
}
cout<<"\nNegative numbers: ";
for(i=0; i<k; i++)
{
cout<<negative[i]<<" ";
}

cout<<endl;
system("pause");
return 0;
}

Algorithm:
1. Start
2. Initialize arr[10], positive[10], negative[10], zero[10], l=0, i=0, j=0, k=0.
3. If i<=9, then input the value of arr[i].
4. Increment i to 1.
5. Repeat step 3 and 4.
6. for(i=0; i<=9; i++), then
7. if arr[i]==0, then initialize zero[l]=arr[i]
increment l to one.
Repeat step 7.
8. If arr[i]>0, then positive[j]=arr[i].
Increment j to 1.
9. Else negative[k]=arr[i]
Increment k to 1.
10. If i<l, then display zero[i].
11. If i<j, then display positive[i].
12. If i<k, then display negative[i].
13. Stop.
Flowchart:

Start

Int arr[10], positive[10],


negative[10], zero[10],
l=0, i=0, j=0, k=0.

If T
i<=9 Input
Increment i+1
? arr[i]

If T If T
i<=9 arr[i]==0 zero[l]=arr[i]
? ?

Increment l+1
F F

A
If T
arr[i]>0 positive[j]=arr[i]
?

Increment j+1
F

A negative[k]=arr[i]

Increment k+1

If T
i<l zero[i] Increment i+1 A
?

If T
i<j positive[i] Increment i+1
?

If T
i<k negative[i] Increment i+1
?

Stop

You might also like