fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_VALUE 2000000001L
  5.  
  6. int main(void) {
  7. int n,*array,i,j,minsum = MAX_VALUE,index1 = 0,index2 = 0,tmp;
  8. FILE *input;
  9. if(!(input = fopen("operators.in","r"))) {
  10. printf("Could not open input file\n");
  11. return 1;
  12. }
  13. fscanf(input,"%d",&n);
  14. if(!(array = (int *) malloc(n * sizeof(int)))) {
  15. printf("Could not allocate space for array\n");
  16. }
  17. for(i = 0; i < n; i++)
  18. fscanf(input,"%d",&array[i]);
  19. printf("The numbers are:\n");
  20. for(i = 0; i < n; i++)
  21. printf("%d ",array[i]);
  22. putchar('\n');
  23.  
  24. //Find min:
  25. for( i = 0; i < (n - 1); i++) {
  26. for(j = 1; j < n; j++) {
  27. if((tmp = ((labs(array[i] + array[j])))) < minsum) {
  28. minsum = tmp;
  29. index1 = i;
  30. index2 = j;
  31. }
  32. }
  33. }
  34. printf("/--------------\nMinimum Sum: ");
  35. printf("%d %d\n",array[index1], array[index2]);
  36. return 0;
  37. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty