Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* VisualStudio Only */
- #include "stdafx.h"
- unsigned long _faktorial(unsigned long n)
- {
- return n > 1 ? n * _faktorial(n - 1) : 1;
- }
- int main(int argc, char* argv)
- {
- /* Prumer by byl float nebo double */
- int n = 0, cislo = 0, prumer = 0;
- /* Suma muze byt hodne velke cislo (proto long), ale i zaporna (proto ne unsigned long) */
- long suma = 0;
- /* Faktorial bude hodne velky a vzdy kladny => unsigned long */
- unsigned long faktorial = 1;
- printf("Zadej pocet cisel n: ");
- if(!scanf("%i",&n))
- {
- printf("Neplatny vstup.\n");
- return 1;
- }
- if(n < 1)
- {
- printf("Minimum je 1.\n");
- return 1;
- }
- /* Zacatek bloku - potlaci chybove hlaseni a navic omezuje scope promennych */
- {
- int i;
- for(i = 1; i <= n; i++)
- {
- printf("Zadej %i. cislo: ", i);
- if(!scanf("%i",&cislo))
- {
- printf("Neplatny vstup.\n");
- return 1;
- }
- suma += (long) cislo;
- }
- }
- prumer = suma / n;
- printf("Prumer zadanych cisel je: %i \n",prumer);
- if(suma >= 0)
- {
- faktorial = _faktorial(prumer);
- printf("Faktorial prumeru je: %i \n", faktorial);
- }
- else
- {
- printf("Suma < 0, n! neni definovano.\n");
- }
- {
- int soucet = 0, x;
- for(x = 0; x < prumer; x++)
- {
- soucet += x;
- printf("Suma %i je %i \n",x,soucet);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment