Rodex_

LowerSum_Kollege_Array

Feb 26th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.    int count = 1;
  7.  
  8.    double *array = (double*)malloc(count*sizeof(double));
  9.  
  10.    int n=0;
  11.     double last=0;
  12.  
  13.     while(last>=0){
  14.     scanf("%lf",&last);
  15.  
  16.     if(last>=0){
  17.  
  18.         count++;
  19.         array = (double*)realloc(array, count*sizeof(double));
  20.         array[n]=last;
  21.         n++;
  22.     }
  23.     }
  24.  
  25.     double sum=0;
  26.     double smallsum=0;
  27.  
  28.     for(int i=0;i<=n;i++){
  29.         sum=sum+array[i];
  30.     }
  31.  
  32.     double mittelwert=sum/(n);
  33.  
  34.  
  35.     for(int i=0;i<=n;i++){
  36.         if(array[i]<mittelwert){
  37.             smallsum=smallsum+array[i];
  38.         }
  39.     }
  40.  
  41.  
  42.     printf("%.2f",smallsum);
  43.  
  44.  
  45.  
  46.  
  47.    free(array);
  48.  
  49.  
  50.  
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment