Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void beolvas(double* tomb);
  4. void kiir(double* tomb);
  5. void avgc(double* tomb);
  6. void minimax(double* tomb);
  7. void avgelter(double* tomb,double atlg);
  8. int main() {
  9.     double asd[100];
  10.     beolvas(asd);
  11.     kiir(asd);
  12.     avgc(asd);
  13.     minimax(asd);
  14.     printf("Kerem adjon meg egy atlagot amelyre kivanja vizsgalni az elemeket:");
  15.     double atl;
  16.     scanf_s("%lf", &atl);
  17.     avgelter(asd, atl);
  18.    
  19. }
  20. void beolvas(double* tomb) {
  21.     double bekert;
  22.     int ok = 0, i = 0;
  23.     do {
  24.         printf("Kérem adjon meg 3 értéket.\n");
  25.         for (i = 0; i < 3;)
  26.         {
  27.             scanf_s("%lf", &bekert);
  28.             if (bekert > 0 && bekert <= 50) {
  29.                 tomb[i] = bekert;
  30.                 ok = 1;
  31.                 i++;
  32.             }
  33.             else {
  34.                 printf("Error! Kérem adjon meg masik adatot:\n");
  35.                 ok = 0;
  36.             }
  37.         }
  38.  
  39.     } while (ok != 0 && i != 3);
  40. }
  41. void kiir(double* tomb) {
  42.     printf("A tomb elemei:\n");
  43.     for (int j = 0; j < 3; j++)
  44.     {
  45.         printf("%.2lf\n", tomb[j]);
  46.     }
  47. }
  48. void avgc(double* tomb) {
  49.     double avg = 0, sum = 0, db = 0;
  50.     for (int i = 0; i < 3; i++)
  51.     {
  52.         sum = sum + tomb[i];
  53.     }
  54.     avg = sum / 3;
  55.     printf("A tomb elemeinek alaga: %.3lf\n", avg);
  56. }
  57. void minimax(double* tomb) {
  58.     double min = tomb[0], max = tomb[0];
  59.     for (int i = 0; i < 3; i++)
  60.     {
  61.         if (max < tomb[i]) {
  62.             max = tomb[i];
  63.         }
  64.         if (min > tomb[i])
  65.         {
  66.             min = tomb[i];
  67.         }
  68.     }
  69.     printf("A tomb legkissebb eleme:%.2lf\nA tomb legnagyobb eleme:%.2lf\n", min, max);
  70. }
  71. void avgelter(double* tomb, double atlg) {
  72.     printf("A tomb elemeinek atlagtol valo elterese:\n");
  73.     for (int i = 0; i < 3; i++) {
  74.         double szam = tomb[i] - atlg;
  75.         if (szam > 0) {
  76.             printf("+%.1lf,", szam);
  77.         }
  78.         if (szam < 0) {
  79.             printf("%.1lf,", szam);
  80.         }
  81.         if (szam == 0)
  82.         {
  83.             printf("%.1lf\n", szam);
  84.         }
  85.     }
  86.     printf("\n");
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement