How to Create a program in C that accepts a set of integers and finds the number of positive and negative numbers.And the program stops when the user enters 0 for the integer value.
1
Expert's answer
2012-07-05T07:29:00-0400
#include "stdafx.h" #include <iostream>
using namespace std; int main() { int arrayofnumbers[100]; int number=0; cin>>number; int count=0; while(number!=0){ arrayofnumbers[count]=number; count++; cin>>number; } cout<<"Positive numbers: "; for(int i=0;i<count;i++){ if(arrayofnumbers[i]>0){ cout<<arrayofnumbers[i]<<" "; } } cout<<" Negative numbers: "; for(int i=0;i<count;i++){ if(arrayofnumbers[i]<0){ cout<<arrayofnumbers[i]<<" "; } } cin>>number; return 0; }
Comments
Leave a comment