i have a polynomial function p(x)=3x^2+2x-2
how can i get the constant values and exponents for instance
(3,2),(2,0),(-2,0) in a linkes list?
i think i have to get this polynomial function as a string isthis a good way??
This is a discussion on reading a string!!! within the C++ Programming forums, part of the General Programming Boards category; i have a polynomial function p(x)=3x^2+2x-2 how can i get the constant values and exponents for instance (3,2),(2,0),(-2,0) in a ...
i have a polynomial function p(x)=3x^2+2x-2
how can i get the constant values and exponents for instance
(3,2),(2,0),(-2,0) in a linkes list?
i think i have to get this polynomial function as a string isthis a good way??
Last edited by condorx; 12-07-2002 at 10:01 AM.
Do you want to extract numbers from a string?
Kuphryn
Easy.
Input:Code:#include <stdio.h> #include <stdlib.h> typedef struct list{int constant, exponent; struct list *next;}LIST; main(){ int c, e; LIST *head = malloc(sizeof(LIST)), *walk = head; while (scanf("(%d,%d),", &c, &e) == 2){ walk->next = malloc(sizeof(LIST)); walk = walk->next; walk->constant = c; walk->exponent = e; walk->next = 0; } for (walk = head->next; walk; walk = walk->next) printf("(%d,%d)\n", walk->constant, walk->exponent ); }
(3,2),(2,0),(-2,0)
Output:
(3,2)
(2,0)
(-2,0)
simply i want to take the constant values and exponent of x to another integer matrix[5][2]
for instance
p(x)=3x^2+2x
array take all the the integers array[1][0]=3 array[1][1]=2 and so on..
First you want a linked list now you want an array? I think you should make up your mind about how to do it before you start doing it.
no i used array to illustrate what i want?i thought it is easier