Sathvikks8

Lab Program 2

Apr 10th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. //Program 2
  2. #include<stdio.h>
  3. #include<math.h>
  4. void main()
  5. {
  6.     float a,b,c,d,root1,root2,real,imaginary;
  7.     goto input;
  8.     input:
  9.     {
  10.         printf("Enter the values of a, b & c of the quadratic equation ");
  11.         scanf("%f%f%f",&a,&b,&c);
  12.     }
  13.     if(a==0)
  14.     {
  15.         printf("\nThe value of a cannot be zero. It is not a qadratic equation. Try again\n\n");
  16.         goto input;
  17.     }
  18.     d=(b*b)-(4*a*c);
  19.     if(d<0)
  20.     {
  21.         printf("\nThe roots are imaginary ");
  22.         real=(-b)/(2*a);
  23.         imaginary=sqrt(fabs(d))/(2*a);
  24.         printf("and the roots are as follows\n R1 = %f + %fi\n R2 = %f + %fi",real,imaginary,real,imaginary);
  25.     }
  26.     else if(d==0)
  27.     {
  28.         printf("\nThe roots are real and equal ");
  29.         root1=root2=(-b)/(2*a);
  30.         printf("and the roots are as follows\n R1 = %f\n R2 = %f",root1,root2);
  31.     }
  32.     else
  33.     {
  34.         printf("\nThe roots are real and distinct ");
  35.         root1=((-b)+(sqrt(d)))/(2*a);
  36.         root2=((-b)-(sqrt(d)))/(2*a);
  37.         printf("and the roots are as follows\n R1 = %f\n R2 = %f",root1,root2);
  38.     }
  39. }
Add Comment
Please, Sign In to add comment