Condition:

A one-dimensional array of 100 elements is given, consisting of random real numbers in the range from -35 to 50. Output in positive order those that are less than a given number X (0 <X <50) in non-decreasing order (increase).

My code is:

#include <vcl.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused int main(int argc, char *argv[]) { float x[100] = { 0 }, sw, a; char j = 0, i = 0, min; randomize(); for (i = 0; i < 100; i++) x[i] = random(85) - 35 + random(100) / 100.; printf("%f\n", x[i]); for (i = 0; i < 98; i++) { min = i; for (j = i + 1; j < 99; j++) if (x[min] > x[j]) min = j; sw = x[i]; x[i] = x[min]; x[min] = sw; } printf("Vvedite X:"); scanf("%f", &a); i = 0; while (x[i] <= a) { printf("%f\n", x[i]); i++; }; getchar(); getchar(); return 0; } 

Here I have the wrong output ... you must first output the entire array, and then the necessary elements in ascending order (I work in Turbo C ++).

  • four
    hellish code) - Gorets
  • I did not manage to write down in a normal way, it seemed to set 4 spaces, I hope the admin will edit the record to normal ... - smthelse

1 answer 1

Sort the array with std :: sort (if this is C ++, I didn’t notice something by code) or qsort. Then output, starting from the end, while checking the number for belonging to the range.

  • If this is the Turbo C ++ that started from a floppy disk, then there was no concept of namespace in the now familiar sense and the name name space - renegator
  • Then just sort. And where does vcl come from? Is it in Turbo C ++? I thought it was just Delphi and C ++ Builder. - gammaker
  • qsort is still about vcl.h, then it’s still just a leader, it does not oblige the compiler to anything. This is true if the turbo with ++ is exactly the same - with DOS - renegator