
Untitled
By: a guest on
Mar 11th, 2012 | syntax:
None | size: 1.51 KB | hits: 84 | expires: Never
/*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*/
#include <stdio.h>
//int sum_minus(*,int); //prototype for sum of minus array
//int sum_plus(*int, int); //prototype for sum of plus array
int sum(int *a, int);
main()
{
int num, plus[99] = {0}, minus[99]= {0}, count = 0, array_amount, minus_total, plus_total, *a, total;
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 ;
else
minus[count] = num ;
++count ;
}
while( num != 999 );
array_amount = count ;
a = minus[] ; //assign to pointer for function call
int sum(int *a,array_amount) ;
minus_total = total;
a = plus[] ;
int sum(int *a,array_amount) ;
plus_total = total ;
//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) ;
}
//int sum_minus(*a,b)
int sum(int *a, array_amount)
{
int b, total = 0;
for (b = 0, b <= array_amount, b++ )
{
total+=a[b];
} ;
return total;
}