Page 170, Exercise 1
Call: a = ReadPoly();
|
PolyPointer ReadPoly()
{/*read the polynomial into a chain */
PolyPointer front, rear,temp;
float coefficient;
int exponent;
front=rear=NULL;
printf("Enter an exponent Less than 0 to quit: \n");
printf("Coefficient, Exponent: ");
scanf("%f,%d",&coefficient,&exponent);
while (exponent >= 0) {
temp = (PolyPointer)malloc(sizeof(struct PolyNode));
temp->coef = coefficient;
temp->expon = exponent;
temp->link = NULL;
if (!front) front = temp;
else rear->link = temp;
rear = temp;
printf("Coefficient, Exponent: ");
scanf("%f,%d",&coefficient,&exponent);
}
return front;
} |