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
8 1828
Post the code you had written so far....
-
#include<stdio.h>
-
#include<conio.h>
-
#include<math.h>
-
-
main()
-
{
-
int x,y,i,j, total;
-
int bilangan[100];
-
awal:
-
clrscr();
-
for(y=0;y<=99;y++)
-
bilangan[y]=0;
-
printf("Insert polynomial number:");
-
for(i=0;;i++)
-
{
-
scanf("%d",&bilangan[i]);
-
scanf(" ");
-
if(bilangan[i]==13)
-
break;
-
}
-
printf("\nInsert x value:");
-
scanf("%d",&x);
-
total=0;
-
for(j=0;j<=i;j++)
-
total +=bilangan[j]*pow(x, j);
-
printf("\nThe result is %d",total);
-
getch();
-
}
-
-
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.
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?
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
I think your first problem is in reading the polynominal numbers -
for(i=0;;i++)
-
{
-
scanf("%d",&bilangan[i]);
-
scanf(" ");
-
if(bilangan[i]==13)
-
break;
-
}
-
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. -
for(i=0;;i++)
-
{
-
scanf("%d",&bilangan[i]);
-
// scanf(" "); you don't need this!
-
if(bilangan[i]==0) // replace 13 with 0
-
break;
-
}
-
so you would enter 5 4 3 2 1 0 then the value of x
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.
I think yhe program still don't work well.
Pls help me soon
Sign in to post your reply or Sign up for a free account.
Similar topics
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()...
|
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...
|
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 ();
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |