/*4. write a program which will accept both positive and negative integers
from the user until 999 is entered to stop the prog.
sum up both sets of num separately and determine the smallest and largest num from both sets, display these results.
by Carey Riley, Student ID MO/10/7220/MS*/
#include
#include
//int sum_minus(*,int); //prototype for sum of minus array
//int sum_plus(*int, int); //prototype for sum of plus array
int sum(int *, int);
main()
{
int num, count = 0, minus_total, plus_total, total;//*a, //array_amount,;
int *plus, *minus;
printf("Enter 999 to exit.\n\n");
do{ //start of request loop
printf("Enter an integer, negative or positive:\n");
scanf("%i",&num);
/*procedure to fill array*/
if(num >= 0)
{
*(plus + count) = &num ;
count ++;
}
else
{
*(minus + count) = &num ;
count++ ;
}
}
while( num != 999 );
//array_amount = count ;
//a = plus ;//assign to pointer for function call
plus_total = sum(plus, count) - 999 ;
//a = minus ; //assign to pointer for function call
minus_total = sum(minus, count) ;
/*How do I sort the elements in an array?*/
//printout of totals
printf("The sum of negative integers is %i.\n", minus_total);
printf("The sum of positive integers is %i.\n\n", plus_total);
//minus_total > plus_total ? printf("%i is a larger number than %i.", minus_total, plus_total) : printf("%i is a larger number than %i.", plus_total, minus_total) ;
getchar();
}
//int sum_minus(*a,b)
int sum(int *a, int populace)
{
int b, total = 0;
for (b = 0; b <= populace; b++ )
{
total+=*(a+b);
} ;
return total;
}