peterzig

iteracyjne

Nov 28th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. // iteracyjne.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <conio.h>
  6.  
  7. int main()
  8. {
  9.     float liczba, suma = 0, srednia;
  10.     int licznik = 0;
  11.     printf("Podaj kolejne liczby, 0 konczy wprowadzanie \n");
  12.     do
  13.     {
  14.         licznik++;
  15.         scanf("%f", &liczba);
  16.         suma += liczba;
  17.     }
  18.     while (liczba != 0);
  19.     if (liczba == 0 && licznik == 1)
  20.     {
  21.         printf("Koniec");
  22.     }
  23.  
  24.     else if (liczba == 0 && licznik != 1)
  25.     {
  26.         printf("Suma    = %f\n", suma);
  27.         srednia = suma / (licznik - 1);
  28.         printf("Srednia = %f\n", srednia);
  29.     }
  30.     _getch();
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment