Advertisement
tdulik

Hledani minima vc. kontroly

Aug 24th, 2020
1,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <float.h>
  5. #include <stdbool.h>
  6. typedef struct {
  7.     double cislo;
  8.     bool konec;
  9. } mujTyp;
  10.  
  11. mujTyp zadavaniCisla() {
  12.     int status;
  13.     mujTyp vysledek;
  14.     do {
  15.         status = scanf("%lf", &vysledek.cislo);
  16.         if (status == 0) {
  17.             char pole[256];
  18.             int status2 = scanf("%255s", pole);
  19.             if (pole[0] == 'k') {
  20.                 vysledek.konec = true;
  21.                 return vysledek;
  22.             }
  23.             printf("Zadal jste chybnou hodnotu: '%s', zkuste to znovu!\n", pole);
  24.         }
  25.     } while (status == 0);
  26.     vysledek.konec = false;
  27.     return vysledek;
  28. }
  29.  
  30. int main() {
  31.     double minimum = DBL_MAX;
  32.     bool prvni = true;
  33.     printf("Zadejte radu cisel pro vyhledani minima, konec=K\n");
  34.  
  35.     int status;
  36.     mujTyp vysl;
  37.     do {
  38.         vysl = zadavaniCisla();
  39.         if (prvni) {
  40.             if (vysl.konec)  {
  41.                 printf("Nezadano zadne cislo, koncime...\n");
  42.                 return 0;
  43.             }
  44.             minimum = vysl.cislo;
  45.             prvni = false;
  46.         }
  47.         else {
  48.             if (vysl.konec) {
  49.                 printf("Minimum = %f\n", minimum);
  50.                 return 0;
  51.             }
  52.             if (vysl.cislo < minimum)   minimum = vysl.cislo;
  53.         }
  54.     } while (1);
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement