Advertisement
Kacper_Michalak

Lab 1 Progi

Oct 23rd, 2022
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.  
  8.     int a, b, c;
  9.     float x1, x2, delta, p;
  10.     printf("Podaj wartosc a:\n");
  11.     scanf("%d", &a);
  12.     printf("Podaj wartosc b: \n");
  13.     scanf("%d", &b);
  14.     printf("Podaj wartosc c: \n");
  15.     scanf("%d", &c);
  16.  
  17.  
  18.  
  19.     if( a != 0)
  20.     {
  21.         delta = ( b * b) - (4 * a * c);
  22.         if(delta > 0)
  23.         {
  24.             p = sqrt(delta);
  25.             x1 = (b *(-1) + p) / (2 * a);
  26.             x2 = (b *(-1) - p) / (2 * a);
  27.  
  28.             printf("Funkcja kwadratowa ma dwa miejsca zerowe x1=%f i x2=%f \n", x1,x2);
  29.  
  30.         } else if( delta == 0)
  31.         {
  32.             x1 = (b * (-1)) / (2 *a);
  33.             printf("Funkcja kwadratowa ma jedno miejsce zerowe x1 = %f \n", x1);
  34.         }else
  35.         {
  36.             printf("Delta jest ujemna podana funkcja kwadratowa nie ma miejsc zerowych \n");
  37.         }
  38.     }else
  39.     {
  40.         printf("Podana funkcja kwadratowa nie istnieje \n");
  41.     }
  42.  
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement