Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 462957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:07:38+00:00 2026-05-12T23:07:38+00:00

So I have a polynomial that looks like this: -4x^0 + x^1 + 4x^3

  • 0

So I have a polynomial that looks like this: -4x^0 + x^1 + 4x^3 – 3x^4
I can tokenize this by space and ‘+’ into: -4x^0, x^1, 4x^3, -, 3x^4

How could I just get the coefficients with the negative sign: -4, 1, 0, 4, -3
x is the only variable that will appear and this will alway appear in order
im planning on storing the coefficients in an array with the array index being the exponent
so: -4 would be at index 0, 1 would be at index 1, 0 at index 2, 4 at index 3, -3 at index 4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:07:38+00:00Added an answer on May 12, 2026 at 11:07 pm

    Once you have tokenized to “-4x^0”, “x^1”, etc. you can use strtol() to convert the textual representation into a number. strtol will automatically stop at the first non-digit character so the ‘x’ will stop it; strtol will give you a pointer to the character that stoped it, so if you want to be paranoid, you can verify the character is an x.

    You will need to treat implicit 1’s (i.e. in “x^1” specially). I would do something like this:

    long coeff;
    if (*token == 'x')
    {
       coeff = 1;
    }
    else
    {
        char *endptr;
        coeff = strtol(token, &endptr, 10);
        if (*endptr != 'x')
        {
            // bad token
        }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that looks like this: public class Polynomial { List<Term> term =
I currently have a class called Polynomial, The initialization looks like this: def __init__(self,
If I have a parent-child that defines some method .foo() like this: class Parent
I have a polynomial P and I would like to find y such that
I have a function specification that states it that should evaluate a polynomial function
I have a range of data that I have approximated using a polynomial of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
When we have a high degree linear polynomial that is used to fit a
I have a command that I can run on the command line to tilt-shift
i have NP hard problem. Let imagine I have found some polynomial algorithm that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.