pascal programming

2006-10-20 2:26 am
wrire a PASCAL program that will ask the coefficient of a polynomial, and then produce the output that print out the polynomial and the output value for the value of x.
Sample output
what is the coefficient of the x^3 term? 1
what is the coefficient of the x^2 term? 2
what is the coefficient of the x term? 3
what is the constant term? 5
what is the value of x? 5
The polynomial is (x)^3 + 2(x)^2 + 3(x) + 5
when x=5, the polynomial =195
個program應該點打ar??

回答 (2)

2006-10-20 10:39 am
✔ 最佳答案
program Polynomial(Input, Output);

uses wincrt;

var coeff : array [1..3] of integer;
constant : integer;
x : integer;

begin
write(’What is the coefficient of the x^3 term? ’);
readln(coeff[3]);

write(’What is the coefficient of the x^2 term? ’);
readln(coeff[2]);

write(’What is the coefficient of the x term? ’);
readln(coeff[1]);

write(’What is the constant term? ’);
readln(constant);

write(’What is the value of x? ’);
readln(x);

write(’The polynomial is ’);

if (coeff[3] <> 1) then
write(coeff[3]);
write(’(x)^3 ’);

if (coeff[2] <> 1) then
write(coeff[2]);
write(’(x)^2 + ’);

if (coeff[1] <> 1) then
write(coeff[1]);
write(’(x) + ’);

writeln(constant);

writeln(’When x=’, x, ’the polynomial = ’, coeff[3]*x*x*x + coeff[2]*x*x + coeff[1]*x + constant);
end.
2006-10-24 7:54 am
Use write and read, x*x*x for x^3, OK gar la.


收錄日期: 2021-04-12 23:32:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061019000051KK02839

檢視 Wayback Machine 備份