473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Polynomial number

21
Hi friends, I need your help in making program in polybomial number.
The program let us give input:constanta and x
And the output is: the result
Let me give the example of the program's output
"Please input coefficient = 5 4 3 2 1"
"Please input x value = 3"
"The result is 547"

Note: bold number can be changed depends on our input and sorry if my english is bad.

Thx for all your help
Feb 5 '07 #1
8 1828
Post the code you had written so far....
Feb 5 '07 #2
Budiman
21
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4.  
  5. main()
  6. {
  7.      int x,y,i,j, total;
  8.      int bilangan[100];
  9.      awal:
  10.      clrscr();
  11.      for(y=0;y<=99;y++)
  12.          bilangan[y]=0;
  13.      printf("Insert polynomial number:");
  14.      for(i=0;;i++)
  15.      {
  16.         scanf("%d",&bilangan[i]);
  17.         scanf(" ");
  18.         if(bilangan[i]==13)
  19.             break;
  20.      }
  21.      printf("\nInsert x value:");
  22.      scanf("%d",&x);
  23.      total=0;
  24.      for(j=0;j<=i;j++)
  25.         total +=bilangan[j]*pow(x, j);
  26.      printf("\nThe result is %d",total);
  27.      getch();
  28. }
  29.  
  30.  
I hope all of you check the false of this program.
I don't where's part wrong.
I hope all your help soon coz the deadline of this assignment is tommorrow morning.
Feb 6 '07 #3
Ganon11
3,652 Expert 2GB
Let me try to explain the problem as I see it:

The user will enter some number of integers. These integers represent the coefficients of a polynomial. Thus, if the user enters 5 4 3 2 1, this is to be interpreted as 5x^4 + 4x^3 + 3x^2 + 2x + 1. The user is then asked for an x value, and the polynomial will be evaluated at that x value. Thus, if the user enters 3 for the x value, then the output will be f(3) = 5(3)^4 + 4(3)^3 + 3(3)^2 + 2(3) + 1 = 547.

Is this correct?
Feb 6 '07 #4
Budiman
21
Yes, you correct. but that program still have the mistakes.
I hope you help me to solve the problem.
Please tell me where is the wrong part of that program
Feb 6 '07 #5
horace1
1,510 Expert 1GB
I think your first problem is in reading the polynominal numbers
Expand|Select|Wrap|Line Numbers
  1.      for(i=0;;i++)
  2.      {
  3.         scanf("%d",&bilangan[i]);
  4.         scanf(" ");
  5.         if(bilangan[i]==13)
  6.             break;
  7.      }
  8.  
i guess the ==13 is testing for the newline character - this will not work as newline is whitespace and skipped by scanf() when using the conversion specification %d. What you can do is terminate the input on a 0, e.g.
Expand|Select|Wrap|Line Numbers
  1.      for(i=0;;i++)
  2.      {
  3.         scanf("%d",&bilangan[i]);
  4.       //  scanf(" ");  you don't need this!
  5.         if(bilangan[i]==0)  // replace 13 with 0
  6.             break;
  7.      }
  8.  
so you would enter 5 4 3 2 1 0 then the value of x
Feb 6 '07 #6
Ganon11
3,652 Expert 2GB
But that would not be desriable, as there may be a polynomial to be evaluated with a coefficient of 0, such as x^2 + 1, which would be entered as 1 0 1.

Perhaps you could ask the user what degree the function is (the degree equals the highest exponent) and read in that many (plus 1 for the constant value) integers as coefficients.
Feb 6 '07 #7
Budiman
21
Ok I'll try it first
Feb 7 '07 #8
Budiman
21
I think yhe program still don't work well.
Pls help me soon
Feb 7 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Just | last post by:
While googling for a non-linear equation solver, I found Math::Polynomial::Solve in CPAN. It seems a great little module, except it's not Python... I'm especially looking for its poly_root()...
9
by: strotee76 | last post by:
What do I need to do to setTerm() for it to work properly? If you notice any other glaring issues, then please let me know. With this header file: ======================= #ifndef Polynomial_h...
1
by: Rubén Campos | last post by:
I've trying to implement polynomials of arbitrary order as a C++ template, as shown here: template <unsigned long int N> class Polynomial { public: Polynomial (); ~Polynomial ();
2
by: temper3243 | last post by:
Hi, I have been trying to solve the problem Roots of the polynomial 038 from mipt.ru (el judge). I have failed to do so. I tried to search on the net but found about contour integrals for...
2
by: UnixUser | last post by:
I need to know what the table is for a crc32 with a Polynomial of 0X04c11db7? Is there a way to prove the result. In other words given the test "the cat and dog ran down the street" what is the...
2
by: Chen L. | last post by:
Hi all, If I have a 32-bit data M, and the CRC genrator polynomial G(x),which power is 32, then I can get the CRC checkword R by the following algorithm: X^32*M(x) = Q(x)G(x) + R(x), But how...
14
by: Tiza Naziri | last post by:
Hi, Anybody have an idea on how to start writing a C code for generating the inverse of finite field GF(2^8) using extended Euclidean algorithm? What I mean is how to represent a polynomial,...
12
by: daniel.wolff | last post by:
I am looking for a quick C program that takes n+1 pairs of values (integers) (a_i, f(a_i)), i=0,...,n, generates the coefficients \alpha_i, i=0,...,n of the polynomial of degree n that fits these...
1
by: madman228 | last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial in which i need a derivative method I have everything, just dont know how to start the derivative method. Any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.