Code Competitions

Coding competition

Sunday, 12 May 2013

Program to find roots of polynomial equation

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    float a,b,c,x1,x2,d;
    clrscr();
    printf("enter the values of a,b,c");
    scanf("%f%f%f",&a,&b,&c);
    d=b*b-4*a*c;
    if(d>0)
    {
        x1=(-b+sqrt(d))/2;
        x2=(-b-sqrt(d))/2;
        printf("roots are x1,x2 =%f,%f",x1,x2);
    }
    else if(d==0)
    {
        x1=x2=-b/(2*a);
        printf("roots are x1,x2 =%f,%f",x1,x2);
    }
    else
    {
        printf("roots are imaginary");
    }
    getche();
}

8 comments:

  1. Ajay i need a c++ pgm " the elements of the field F4 are the roots of the polynomial x4-x=x(x-1)(x2+x+1)"

    (x raise to 4 and x raise to 2)

    ReplyDelete
  2. sure sir, but need to clear about the equation should be static that you mentioned
    or
    general purpose..

    ReplyDelete
  3. you can send me mail also, by elaborating the problem

    ReplyDelete
    Replies
    1. a programme to find the roots of a polynomial equation in Zn .
      Applications in modern algebra.
      for example : Find the roots of a 2x^2 + 5x + 9 in Z7. The roots will be different for different Zn . Like the roots of the given equation in Z7 ,Z8 and Z9..... are different.

      Delete
  4. Ajay i need a c++ pgm code abt Finite field in Mathematics
    ' The elements of the field F4 are the roots of the ploynomial x4-x=x(x-1)(x2+x+1)

    x4 means raise to 4
    x2 means raise to 2

    ReplyDelete
  5. dear, we can use hit and trial method in any equation to solve, may be of any degree. i will post but takes time. because of busy.. :(. But i shall post the solution.

    to solve first put all integer values from -32768 to 32767. but it will give only integer roots . not imaginary, not float type

    ReplyDelete
  6. cant do it like if i enter x^2+2x+1 or any other eqn directly

    ReplyDelete
  7. C++ program to find Square Root of a Number

    Thanks for sharing this code. It's really helpful. Keep sharing.

    ReplyDelete