Buri

Betty C ukol

Oct 22nd, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. /* VisualStudio Only */
  2. #include "stdafx.h"
  3.  
  4. unsigned long _faktorial(unsigned long n)
  5. {
  6.     return n > 1 ? n * _faktorial(n - 1) : 1;
  7. }
  8.  
  9. int main(int argc, char* argv)
  10. {
  11.     /* Prumer by byl float nebo double */
  12.     int n = 0, cislo = 0, prumer = 0;
  13.  
  14.     /* Suma muze byt hodne velke cislo (proto long), ale i zaporna (proto ne unsigned long) */
  15.     long suma = 0;
  16.  
  17.     /* Faktorial bude hodne velky a vzdy kladny => unsigned long */
  18.     unsigned long faktorial = 1;
  19.  
  20.     printf("Zadej pocet cisel n: ");
  21.     if(!scanf("%i",&n))
  22.     {
  23.         printf("Neplatny vstup.\n");
  24.         return 1;
  25.     }
  26.     if(n < 1)
  27.     {
  28.         printf("Minimum je 1.\n");
  29.         return 1;
  30.     }
  31.     /* Zacatek bloku - potlaci chybove hlaseni a navic omezuje scope promennych */
  32.     {
  33.         int i;
  34.         for(i = 1; i <= n; i++)
  35.         {
  36.             printf("Zadej %i. cislo: ", i);
  37.             if(!scanf("%i",&cislo))
  38.             {
  39.                 printf("Neplatny vstup.\n");
  40.                 return 1;
  41.             }
  42.             suma += (long) cislo;
  43.         }
  44.     }
  45.  
  46.     prumer = suma / n;
  47.     printf("Prumer zadanych cisel je: %i \n",prumer);
  48.  
  49.     if(suma >= 0)
  50.     {
  51.         faktorial = _faktorial(prumer);
  52.         printf("Faktorial prumeru je: %i \n", faktorial);
  53.     }
  54.     else
  55.     {
  56.         printf("Suma < 0, n! neni definovano.\n");
  57.     }
  58.  
  59.     {
  60.         int soucet = 0, x;
  61.         for(x = 0; x < prumer; x++)
  62.         {
  63.             soucet += x;
  64.             printf("Suma %i je %i \n",x,soucet);
  65.         }
  66.     }
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment