fork(1) download
  1. /*4. write a program which will accept both positive and negative integers
  2. from the user until 999 is entered to stop the prog.
  3. sum up both sets of num separately and determine the smallest and largest num from both sets, display these results.
  4.  
  5. by Carey Riley, Student ID MO/10/7220/MS*/
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. //int sum_minus(*,int); //prototype for sum of minus array
  11. //int sum_plus(*int, int); //prototype for sum of plus array
  12.  
  13. int sum(int *, int);
  14.  
  15. main()
  16. {
  17. int num, count = 0, minus_total, plus_total, total;//*a, //array_amount,;
  18. int *plus, *minus;
  19. printf("Enter 999 to exit.\n\n");
  20. do{ //start of request loop
  21. printf("Enter an integer, negative or positive:\n");
  22. scanf("%i",&num);
  23.  
  24. /*procedure to fill array*/
  25.  
  26. if(num >= 0)
  27. {
  28. *(plus + count) = &num ;
  29. count ++;
  30. }
  31. else
  32. {
  33. *(minus + count) = &num ;
  34. count++ ;
  35. }
  36. }
  37. while( num != 999 );
  38.  
  39. //array_amount = count ;
  40.  
  41. //a = plus ;//assign to pointer for function call
  42.  
  43.  
  44. plus_total = sum(plus, count) - 999 ;
  45.  
  46. //a = minus ; //assign to pointer for function call
  47. minus_total = sum(minus, count) ;
  48. /*How do I sort the elements in an array?*/
  49.  
  50.  
  51. //printout of totals
  52.  
  53. printf("The sum of negative integers is %i.\n", minus_total);
  54. printf("The sum of positive integers is %i.\n\n", plus_total);
  55.  
  56. //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) ;
  57. }
  58.  
  59. //int sum_minus(*a,b)
  60. int sum(int *a, int populace)
  61. {
  62. int b, total = 0;
  63. for (b = 0; b <= populace; b++ )
  64. {
  65. total+=*(a+b);
  66. } ;
  67. return total;
  68. }
  69.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty