Telaryon

Másodfokú egyenlet számítás

Mar 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int gyokalatt(a,b,c);
  5. int tortalatt(a);
  6. double szamitas(a,b,c,temp1,temp2);
  7. double szamitass(a,b,c,temp1,temp2);
  8.  
  9.  
  10. int main(void){
  11.     int a;
  12.     int b;
  13.     int c;
  14.     int temp1;
  15.     int temp2;
  16.     double x1;
  17.     double x2;
  18.  
  19.     printf("a erteke: ");
  20.     scanf("%d", &a);
  21.     printf("b erteke: ");
  22.     scanf("%d", &b);
  23.     printf("c erteke: ");
  24.     scanf("%d", &c);
  25.     temp1=gyokalatt(a,b,c);
  26.     temp2=tortalatt(a);
  27.     if (temp1<0)
  28.     {
  29.         printf("matematikai hiba");
  30.         return 1;
  31.     }
  32.     if (temp2==0)
  33.     {
  34.         printf("matematikai hiba");
  35.         return 2;
  36.     }
  37.     printf("%d, %d, %d, %d, %d,\n", a, b, c, temp1, temp2);
  38.     x1=szamitas(a,b,c,temp1,temp2);
  39.     x2=szamitass(a,b,c,temp1,temp2);
  40.     printf("Az elso megoldas %lf\n", x1);
  41.     printf("A masodik megoldas %lf\n", x2);
  42.     return 0;
  43. }
  44.  
  45. int gyokalatt(a,b,c)
  46. {
  47.     int r;
  48.     r=pow(b,2)-(4*a*c);
  49.     return r;
  50. }
  51. int tortalatt(a)
  52. {
  53.     int n;
  54.     n=2*a;
  55.     return n;
  56. }
  57. double szamitas(a,b,c,temp1,temp2)
  58. {
  59.     double x1;
  60.     x1=((-b)+sqrt(temp1))/temp2;
  61.     return x1;
  62. }
  63. double szamitass(a,b,c,temp1,temp2)
  64. {
  65.     double x2;
  66.     x2=((-b)-sqrt(temp1))/temp2;
  67.     return x2;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment