ifinox

PP 17.10

Oct 17th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. int main()
  7. {
  8.     int x;
  9.     int suma = 0;
  10.     int iloczyn = 1;
  11.     int iloscLiczb = 0;
  12.     printf("Podaj ciag liczb zakonczony zerem: ");
  13.     do {
  14.         scanf("%d", &x);
  15.         if (x != 0)
  16.         {
  17.             iloscLiczb++;
  18.             suma += x;
  19.             iloczyn *= x;
  20.         }
  21.     } while(x != 0);
  22.  
  23.     printf("Suma liczb: %i\n", suma);
  24.     printf("Iloczyn liczb: %i\n", iloczyn);
  25.     printf("Srednia liczb: %f\n", suma/(float)iloscLiczb);
  26.     system("PAUSE");
  27. }
  28.  
  29.  
  30.  
  31.  
  32. /*
  33. void isInSquare(float x, float y)
  34. {
  35.     if (fabs(x) > 1 || fabs(y) > 1)
  36.         printf("Punkt (%f; %f) NIE nalezy do kwadratu!\n", x,y);
  37.     else
  38.         printf("Punkt (%f; %f) nalezy do kwadratu!\n", x,y);
  39. }
  40.  
  41. void isInCircle(float x, float y, float r)
  42. {
  43.     if (sqrt(x*x + y*y) > r)
  44.         printf("Punkt nie nalezy do kola!\n");
  45.     else
  46.         printf("Punkt nalezy do kola!\n");
  47. }
  48.  
  49. float f1X(float x)
  50. {
  51.     if (x<=0.f)
  52.         return x + 1;
  53.     return x*x;
  54. }
  55. float f2X(float x)
  56. {
  57.     if (x!=0.f)
  58.         return 1/x;
  59.     return 2;
  60. }
  61.  
  62. float w1(float a, float b, float c)
  63. {
  64.     return (a+b+c)/3;
  65. }
  66.  
  67. float w2(float a, float b, float c)
  68. {
  69.     return pow(fabs(a*b*c), 1.0/3);
  70. }
  71.  
  72.  
  73. int main()
  74. {
  75.     printf("Podaj x a nastepnie numer funkcji (1/2) do policzenia: ");
  76.     float x;
  77.     int option;
  78.     scanf("%f %d", &x, &option);
  79.  
  80.     switch(option)
  81.     {
  82.     case 1:
  83.         printf("Wartosc funkcji: %f\n", f1X(x));
  84.         break;
  85.     case 2:
  86.         printf("Wartosc funkcji: %f\n", f2X(x));
  87.         break;
  88.     default:
  89.         printf("Niepoprawna opcja!\n");
  90.     }
  91.     system("PAUSE");
  92. }
  93. */
  94. /*
  95. int main()
  96. {
  97.     while(1){
  98.  
  99.     float x, y;
  100.     printf("Podaj wartosci x i y oddzielone spacja: ");
  101.     scanf("%f %f", &x, &y);
  102.  
  103.     int option;
  104.     printf("Podaj opcje programu (0 dla kwadratu, 1 dla kola, 2 aby wyjsc): ");
  105.     scanf("%d", &option);
  106.  
  107.     float r;
  108.     switch(option)
  109.     {
  110.     case 0:
  111.         isInSquare(x, y);
  112.         break;
  113.     case 1:
  114.         printf("Podaj dlugosc promienia kola: ");
  115.         scanf("%f", &r);
  116.         isInCircle(x,y,r);
  117.         break;
  118.     case 2:
  119.         return 0;
  120.     default:
  121.         printf("Niepoprawna opcja!\n");
  122.     }
  123.     printf("\n");
  124.  
  125.     }
  126.  
  127.     return 0;
  128. }
  129. */
Advertisement
Add Comment
Please, Sign In to add comment