Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 11th, 2012  |  syntax: None  |  size: 1.51 KB  |  views: 88  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. #include <stdio.h>
  6.  
  7. //int sum_minus(*,int); //prototype for sum of minus array
  8. //int sum_plus(*int, int); //prototype for sum of plus array
  9.  
  10. int sum(int *a, int);
  11.  
  12. main()
  13. {
  14.     int num, plus[99] = {0}, minus[99]= {0}, count = 0, array_amount, minus_total, plus_total, *a, total;
  15.  
  16.     do{  //start of request loop
  17.         printf("Enter an integer, negative or positive:\n");
  18.         scanf("%i",&num);
  19.  
  20.         /*procedure to fill array*/
  21.  
  22. if(num >= 0)
  23. plus[count] = num ;
  24. else
  25. minus[count] = num ;
  26.         ++count ;
  27.         }
  28.     while( num != 999 );
  29.  
  30. array_amount = count ;
  31.  
  32. a = minus[] ; //assign to pointer for function call
  33.  
  34. int sum(int *a,array_amount) ;
  35.  
  36. minus_total = total;
  37.  
  38. a = plus[] ;
  39.  
  40. int sum(int *a,array_amount) ;
  41.  
  42. plus_total = total ;
  43.  
  44. //printout of totals
  45.  
  46. printf("The sum of negative integers is %i.\n", minus_total);
  47. printf("The sum of positive integers is %i.\n\n", plus_total);
  48.  
  49. 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) ;
  50. }
  51.  
  52. //int sum_minus(*a,b)
  53. int sum(int *a, array_amount)
  54. {
  55.     int b, total = 0;
  56.     for (b = 0, b <= array_amount, b++ )
  57.     {
  58.         total+=a[b];
  59.     } ;
  60.         return total;
  61.  
  62. }
clone this paste RAW Paste Data