Facebook
From asd, 6 Years ago, written in C.
This paste is a reply to Re: Untitled from asd - view diff
Embed
Download Paste or View Raw
Hits: 448
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.     double stoper,x;
  8.     double sg= 1 ;
  9.     int liczba=0;
  10.     double wprowadzonaLiczba =0;
  11.     printf("Podaj stoper\n");
  12.     scanf("%lf",&stoper);
  13.     printf("Podaj liczbe\n");
  14.     scanf("%lf",&x);
  15.  
  16.     while(x!=stoper)
  17.     {
  18.         if(x>0)
  19.         {
  20.             sg=sg*x;
  21.             liczba++;
  22.         }
  23.         else
  24.         {
  25.             printf("Podales liczbe mniejsza od 0, musisz podac liczbe wieksza od 0.");
  26.         }
  27.  
  28.         printf("Podaj nastepna liczbe\n");
  29.         scanf("%lf",&x);
  30.     }
  31.  
  32.  
  33.     if(liczba==0)
  34.         printf("Nie ma sredniej geometrycznej");
  35.     else
  36.     {
  37.         double sredniag = pow(sg,1.0/liczba);
  38.         printf("Srednia geometryczna to pierwiastek stopnia %d z %lf\n.Wynosi ona : %lf", liczba, sg, sredniag);
  39.     }
  40.     return 0;
  41. }
  42.  
  43.