Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. int main()
  7. {
  8.     int array[100];
  9.     int counter = 0;
  10.     int x;
  11.     int min, max;
  12.     int sum = 0;
  13.     float avg;
  14.     int minindeks, maxindeks;
  15.  
  16.     printf("Podaj liczby: ");
  17.  
  18.     do
  19.     {
  20.         if (scanf("%d", &x) != 1)
  21.         {
  22.             printf("Incorrect input\n");
  23.  
  24.             return 1;
  25.         }
  26.  
  27.         if (x != -1)
  28.         {
  29.             array[counter] = x;
  30.  
  31.             counter++;
  32.         }
  33.     } while (x != -1 && counter < 100);
  34.  
  35.     if (counter == 0)
  36.     {
  37.         printf("Incorrect input\n");
  38.  
  39.         return 1;
  40.     }
  41.  
  42.     min = array[0];
  43.     for (int i = 1; i < counter; i++)
  44.     {
  45.         if (array[i] < min)
  46.         {
  47.             min = array[i];
  48.             minindeks = i;
  49.         }
  50.     }
  51.  
  52.     max = array[0];
  53.     for (int i = 1; i < counter; i++)
  54.     {
  55.         if (array[i] > max)
  56.         {
  57.             max = array[i];
  58.             maxindeks = i;
  59.         }
  60.     }
  61.  
  62.     for (int i = 0; i < counter; i++)
  63.     {
  64.         sum += array[i];
  65.     }
  66.     avg = (float)sum / counter;
  67.  
  68.     printf("%d\n", counter);
  69.     printf("%d\n", min);
  70.     printf("%d\n", max);
  71.     printf("%f\n", avg);
  72.     printf("%d\n", sum);
  73.     printf("%d\n", minindeks);
  74.     printf("%d\n", maxindeks);
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement