C Program to find value of x by Pythagoras Theorem - Complex Number

How to Write a C Program to find value of x by Pythagoras Theorem - Complex Number in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. void main()
  5. {
  6.  int a,b,c,i,n,j;
  7.  float r,x1,d,x2,e,f,x;
  8.  clrscr();
  9.  printf("Enter Value for a, b and c: ");
  10.  scanf("%d %d %d",&a,&b,&c);
  11.  f=(b/(2*a));
  12.  r=(b*b)-(4*a*c);
  13.  if(r>0)
  14.  {
  15.   d=sqrt(r);
  16.   x=d/(2*a);
  17.   x1=-f+x;
  18.   x2=-f-x;
  19.   printf("x=%.2f, %.2f",x1,x2);
  20.  }
  21.  else
  22.  {
  23.   e=-r;
  24.   d=sqrt(e);
  25.   x=e/(2*a);
  26.   printf("x=(%.2f-i%.2f), (%.2f+i%.2f)",f,x,f,x);
  27.  }
  28.  getch();
  29. }


Learn More :