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 ++).