C Beginner

Discussion in 'C' started by Valiantangel, Apr 15, 2012.

  1. Valiantangel

    Valiantangel New Member

    Joined:
    Apr 14, 2012
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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;     [COLOR="Red"]/*This is giving me problem*/[/COLOR]
    	
    	x=2.55;
    	printf("The value of polynomial is %lf\n",polynomial);
    
    	system("pause");
    
    	return(EXIT_SUCCESS);
    }
     
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    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.
     
  3. Chong

    Chong New Member

    Joined:
    May 15, 2011
    Messages:
    29
    Likes Received:
    7
    Trophy Points:
    0
    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
     
  4. crashcoder

    crashcoder New Member

    Joined:
    Apr 25, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    florida
    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.
     
  5. crashcoder

    crashcoder New Member

    Joined:
    Apr 25, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    florida
    Oh and to use pow function you might need to include <cmath> library, we do in secure shell IDE
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice