Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. // prufung.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. float calc(float arr[], int anzahl )
  7. {
  8.     float summe = 0;
  9.  
  10.     for (int i = 0; i < anzahl; i++)
  11.     {
  12.         summe += arr[i];
  13.        
  14.  
  15.     }
  16.  
  17.     for (int i = 0; i < anzahl; i++)
  18.     {
  19.         arr[i] = summe - arr[i];
  20.        
  21.     }
  22.  
  23.     for (int i = 0; i < anzahl; i++)
  24.     {
  25.         printf("arr[%d] = %f\n", i, arr[i]);
  26.     }
  27.  
  28.     return summe;
  29.  
  30.  
  31.  
  32.  
  33.  }
  34. int main()
  35. {
  36.     float w[65];
  37.     int nw;
  38.     printf("Geben Sie die Anzahl der Elemente ein:\n");
  39.     scanf_s("%d", &nw);
  40.     float Summe;
  41.  
  42.     if (nw > 65  || nw <1)
  43.     {
  44.         printf("Error.\n");
  45.         return 0;
  46.  
  47.     }
  48.    
  49.     printf("Geben Sie die Elemente der Reihe ein:\n");
  50.     for (int i = 0; i < nw; i++)
  51.     {
  52.         scanf_s("%f",&w[i]);
  53.  
  54.     }
  55.  
  56.     for (int i = 0; i < nw; i++)
  57.     {
  58.         printf("arr[%d] = %.2f\n", i, w[i]);
  59.     }
  60.  
  61.     Summe = calc(w, nw);
  62.     printf("Die Summe der Elemente = %.2f\n", Summe);
  63.  
  64.  
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement