我不是 C 爱好者,我不情愿地写这篇文章,作为我任务的一部分。该程序是输入两个多项式并将它们相加并显示它们。我编写了模块来输入和显示,但是程序没有运行。
其中Dev-C++
说我对 main 有多种定义。
#include<stdio.h>
#include<conio.h>
// This is my implementation to add and multiply
// two polynomials using linked list
// So far, it just inputs and displays the polynomial
struct term {
int exp;
int coef;
struct term *next;
};
struct term* addTerm(struct term *polynomial,int exp,int coef){ // adds a term to polynomial
if(polynomial == NULL ){
polynomial = (struct term *)malloc(sizeof(struct term));
polynomial->exp = exp;
polynomial->coef = coef;
}else{
struct term *newTerm = (struct term *)malloc(sizeof(struct term));
newTerm->exp = exp;
newTerm->coef = coef;
polynomial->next = newTerm;
}
return polynomial;
}
void display(struct term *polynomial){ // displays the polynomial
struct term *p = polynomial;
while(p->next != NULL){
printf("+ %dx%d",p->coef,p->exp); p = p->next;
}
}
void main(){ // run it
int i = 5;
int coef = 0;
int exp = 0;
struct term *polynomial = NULL;
while(i++ < 5){
printf("Enter CoEfficient and Exponent for Term %d",i);
scanf("%d %d",&coef,&exp);
polynomial = addTerm(polynomial,exp,coef);
}
display(polynomial);
getch();
}
我如何让它运行?