Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C Beginner (http://www.go4expert.com/forums/c-beginner-t28192/)

Valiantangel 15Apr2012 19:27

C Beginner
 
I am getting errors in the polynomial equation x.I hav no idea whats wrong.This equation was provided.My code is as followed

Code:

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
       
        double x;
        double polynomial=3x^3-5x^2+6;    /*This is giving me problem*/
       
        x=2.55;
        printf("The value of polynomial is %lf\n",polynomial);

        system("pause");

        return(EXIT_SUCCESS);
}


DRK 16Apr2012 14:11

Re: C Beginner
 
1. Every programming language has its specific syntax. You cannot simply write mathematical expression, it is required to use some symbols called operators.
2. You have to assign value to x before you evaluate polynomial.

Chong 17Apr2012 18:34

Re: C Beginner
 
For MS Visual C++, the following will do:

#include <math.h> //or <math>

double x=2.55;
double polynomial = 3*pow(x,3)-5*pow(x,2)+6

crashcoder 26Apr2012 07:59

Re: C Beginner
 
instead of polynomial=3x^3-5x^2+6;
try using the "pow function" polynomial=3*pow(x,( 3))-5*pow(x,(2))+6;
You could declare x as const int x=?; above your polynomial variable;
logically it could work, but id google the pow function to make sure i wrote it right
its been a while since ive used it.

crashcoder 26Apr2012 08:02

Re: C Beginner
 
Oh and to use pow function you might need to include <cmath> library, we do in secure shell IDE


All times are GMT +5.5. The time now is 19:33.