저는 C 애호가가 아니고 제 과제의 일부로 마지 못해이 글을 쓰고 있습니다. 이 프로그램은 두 개의 다항식을 입력하고 추가하여 표시하는 것입니다. 입력 및 표시 할 모듈을 작성했지만 프로그램이 실행되지 않습니다.
여기 Dev-C++
에는 메인에 대한 여러 정의가 있습니다.
#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();
}
실행하려면 어떻게해야합니까?
추측에 따르면 .c
IDE 프로젝트 에는 여러 파일이 있으며 둘 이상의 파일에는 main()
함수가 포함되어 있습니다. 또는 IDE에서 허용하는 경우 동일한 .c
파일을 프로젝트에 두 번 이상 추가했을 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다