當前位置:首頁 » 編程語言 » c語言一元多項式求導
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言一元多項式求導

發布時間: 2022-01-20 18:36:33

❶ 求c語言程序 一元多項式

一元多項式.....你這可包括了差不多所有的一元多項式了。要寫成千上萬個函數來實現。要是簡單的到立方還好說,要是加上求導10次方就真的要寫n多函數了。有點不太現實

❷ 數據結構 一元多項式求導問題

你的測試數據為什麼是0 -1 -1啊?怎麼是三個參數啊?不是應該就兩個么?一個是系數一個是冪啊!

那這樣呢?
==============================================
#include <stdio.h>
#include <malloc.h>
typedef struct polynode
{
int c;
int e;
struct polynode *next;
} poly;
poly *creatpoly()
{
poly *p, *q, *h;
q = NULL, h = NULL;
int c;
int e;

while (e!=-1)
{
scanf("%d%d", &c, &e); /*將scanf位置改變下*/
h = (poly*)malloc(sizeof(poly));
h->c = c;
h->e = e;
h->next = NULL;
if (q == NULL)
q = h;
else
p->next = h;
p = h;
}
return q;
}

poly *qiu(poly *p)
{
poly *s;
s = p;
while (p)
{
p->c = (p->c)*(p->e);
p->e = (p->e) - 1;
p = p->next;
}

return s;
}

void print(poly *p)
{
int i = 0;
if (p->e == - 1)
{
printf("0");
i++;
}

{
while (p->next != NULL)
{
if (p->c != 0)
{
printf("%d %d ", p->c, p->e);
i++;
}
else
;

p = p->next;
}
if (p->next == NULL)
{
if (p->c != 0 && p->e > -1) /*加上約束條件p->e>-1*/
{
printf("%d %d ", p->c, p->e);
i++;
}
else
;
}

if (i == 0)
printf("0");
printf("\n");
}
}

int main()
{
poly *d, *h;
d = creatpoly();
h = qiu(d);
print(h);
getchar();
getchar();
return 0;
}

❸ 鏈表 一元多項式求導問題 C語言

(1)Pt1->expn!=0
(2)Pt1->coef*Pt1->expn
(3)Pt1->expn-1
(4)P2==NULL
(5)Tail=Pt2 或許應該為 (Tail=Pt2)->next=Null

前三個分析不錯
(4)的if.....else..... 語句是給當前計算完成的Pt2找「組織」的
第一次運行的時候P2==Null,這個接點是首節點,Pt2要賦值給P2,終成為函數的返回值
之後再運行判斷,P2都不為Null,這時候應該將節點接於之前的節點後面Tail->next=Pt2
可見Tail用來暫時存放上一個計算結束的節點

所以(5)就是Tail=Pt2,在循環的最後,將當先節點指針賦給Tail
因為緊接著循環就結束了,Pt2會重新賦值為新空間的地址,要先用Tail保存起它

怎麼說這個程序還是不太健壯
如果空格能填兩句的話,(5)還應該填一句Pt2->next=Null,
或者合寫為 (Tail=Pt2)->next=Null
那樣最後一個節點的next為空,代表鏈表結束

好像還有點問題就是,如果原來的多項式就剩一個常數項
那麼調用這個函數,返回空指針,實際應該返回一個單節點 系數為0,指數為0的鏈表
不過填空就只能做到上邊的結果了

❹ c語言,求導

這位是在別人的地方來的,這是地址:
http://blog.csdn.net/qq_26816591/article/details/48690359
//一元多項式的求導
#include<stdio.h>
#include<malloc.h>//動態申請空間的函數的頭文件
typedef struct node //定義節點類型
{
float coef; //多項式的系數
int expn; //多項式的指數
struct node * next; //結點指針域
}PLOYList;
void insert(PLOYList *head,PLOYList *input) //查找位置插入新鏈節的函數,且讓輸入的多項式呈降序排列
{
PLOYList *pre,*now;
int signal=0;
pre=head;
if(pre->next==NULL) {pre->next=input;} //如果只有一個頭結點,則把新結點直接連在後面
else
{
now=pre->next;//如果不是只有一個頭結點,則設置now指針
while(signal==0)
{
if(input->expn < now->expn)
{
if(now->next==NULL)
{
now->next=input;
signal=1;
}
else
{
pre=now;
now=pre->next;//始終讓新輸入的數的指數與最後一個結點中的數的指數比較,小於則插在其後面
}
}
else if( input->expn > now->expn )
{
input->next=now;
pre->next=input;
signal=1;
}//若新結點中指數比最後一個結點即now中的指數大,則插入now之前
else//若指數相等則需合並為一個結點,若相加後指數為0則釋放該結點
{
now->coef=now->coef+input->coef;
signal=1;
free(input);
if(now->coef==0)
{
pre->next=now->next;
free(now);
}
}//else
} //while
}//else
}//void

PLOYList *creat(char ch) //輸入多項式
{
PLOYList *head,*input;
float x;
int y;
head=(PLOYList *)malloc(sizeof(PLOYList)); //創建鏈表頭
head->next=NULL;
scanf("%f %d",&x,&y);//實現用戶輸入的第一個項,包括其指數和系數
while(x!=0)//當用戶沒有輸入結束標志0時可一直輸入多項式的項,且輸入一個創建一個結點
{
input=(PLOYList *)malloc(sizeof(PLOYList)); //創建新鏈節
input->coef=x;
input->expn=y;
input->next=NULL;
insert(head,input); //每輸入一項就將其排序,是的鏈表中多項式呈降序排列
scanf("%f %d",&x,&y);
}
return head;
}
PLOYList *der(PLOYList *head)//多項式求導
{
PLOYList *p;
p = head -> next;
while (p)
{
p -> coef = p -> coef * p -> expn;
p -> expn = p -> expn--;
p = p -> next;
}
return head;
}//將多項式的每項系數和指數相乘得到新的系數,指數減一得到新的指數即完成求導

void print(PLOYList *fun) //輸出多項式,fun指要輸出的多項式鏈表的表頭
{
PLOYList *printing;
int flag=0;
printing=fun->next;
if(fun->next==NULL)//若為空表,則無需輸出
{
printf("0\n");
return;
}
while(flag==0)
{
if(printing->coef>0&&fun->next!=printing)
printf("+");
if(printing->coef==1);
else if(printing->coef==-1)
printf("-");
else
printf("%f",printing->coef);
if(printing->expn!=0) printf("x^%d",printing->expn);
else if((printing->coef==1)||(printing->coef==-1))
printf("1");
if(printing->next==NULL)
flag=1;
else
printing=printing->next;
}
printf("\n");
}
void main()
{
PLOYList *f;
printf(" 註:輸入多項式格式為:系數1 指數1 系數2 指數2 …… ,並以0 0 結束:\n");
printf("請輸入一個一元多項式:");
f = creat('f');
printf("這個多項式為:f(x)= ");
print(f);
printf("求導結果為:F(x)=f'(x)= ");
f=der(f);
print(f);
printf("\n\n");

}

❺ C語言一元多項式求導,以-1 -1結束

while(z!=0)

循環面沒改變z值z直1死循環

❻ C語言 一元多項式的計算 關於x的一元多項式函數化簡器 給定一個關於x的

這位是在別人的地方來的,這是地址:創建鏈表頭head->next=NULL;scanf("%f%d",&x,&y);//實現用戶輸入的第一個項,包括其指數和系數while(x!=0)//當用戶沒有輸入結束標志0時可一直輸入多項式的項,且輸入一個創建一個結點{input=(PLOYList*)malloc(sizeof(PLOYList));//創建新鏈節input->coef=x;input->expn=y;input->next=NULL;insert(head,input);//每輸入一項就將其排序,是的鏈表中多項式呈降序排列scanf("%f%d",&x,&y);}returnhead;}PLOYList*der(PLOYList*head)//多項式求導{PLOYList*p;p=head->next;while(p){p->coef=p->coef*p->expn;p->expn=p->expn--;p=p->next;}returnhead;}//將多項式的每項系數和指數相乘得到新的系數,指數減一得到新的指數即完成求導voidprint(PLOYList*fun)//輸出多項式,fun指要輸出的多項式鏈表的表頭{PLOYList*printing;intflag=0;printing=fun->next;if(fun->next==NULL)//若為空表,則無需輸出{printf("0\n");return;}while(flag==0){if(printing->coef>0&&fun->next!=printing)printf("+");if(printing->coef==1);elseif(printing->coef==-1)printf("-");elseprintf("%f",printing->coef);if(printing->expn!=0)printf("x^%d",printing->expn);elseif((printing->coef==1)||(printing->coef==-1))printf("1");if(printing->next==NULL)flag=1;elseprinting=printing->next;}printf("\n");}voidmain(){PLOYList*f;printf("註:輸入多項式格式為:系數1指數1系數2指數2……,並以00結束:\n");printf("請輸入一個一元多項式:");f=creat('f');printf("這個多項式為:f(x)=");print(f);printf("求導結果為:F(x)=f'(x)=");f=der(f);print(f);printf("\n\n");}

❼ 如何用C語言實現一元多項式簡單計算器的設計

  1. 一元多項式簡單的計算器的功能:
    1)輸入並建立多項式;
    2)輸出多項式;
    3)兩個多項式相加,輸出和多項式;
    4)兩個多項式相減,輸出差多項式。

  2. 常式

    #include<dos.h>/*DOS介面函數*/
    #include<math.h>/*數學函數的定義*/
    #include<conio.h>/*屏幕操作函數*/
    #include<stdio.h>/*I/O函數*/
    #include<stdlib.h>/*庫函數*/
    #include<stdarg.h>/*變數長度參數表*/
    #include<graphics.h>/*圖形函數*/
    #include<string.h>/*字元串函數*/
    #include<ctype.h>/*字元操作函數*/
    #defineUP0x48/*游標上移鍵*/
    #defineDOWN0x50/*游標下移鍵*/
    #defineLEFT0x4b/*游標左移鍵*/
    #defineRIGHT0x4d/*游標右移鍵*/
    #defineENTER0x0d/*回車鍵*/
    void*rar;/*全局變數,保存游標圖象*/
    structpalettetypepalette;/*使用調色板信息*/
    intGraphDriver;/*圖形設備驅動*/
    intGraphMode;/*圖形模式值*/
    intErrorCode;/*錯誤代碼*/
    intMaxColors;/*可用顏色的最大數值*/
    intMaxX,MaxY;/*屏幕的最大解析度*/
    doubleAspectRatio;/*屏幕的像素比*/
    voiddrawboder(void);/*畫邊框函數*/
    voidinitialize(void);/*初始化函數*/
    voidcomputer(void);/*計算器計算函數*/
    voidchangetextstyle(intfont,intdirection,intcharsize);/*改變文本樣式函數*/
    voidmwindow(char*header);/*窗口函數*/
    intspecialkey(void);/*獲取特殊鍵函數*/
    intarrow();/*設置箭頭游標函數*/
    /*主函數*/
    intmain()
    {
    initialize();/*設置系統進入圖形模式*/
    computer();/*運行計算器*/
    closegraph();/*系統關閉圖形模式返迴文本模式*/
    return(0);/*結束程序*/
    }
    /*設置系統進入圖形模式*/
    voidinitialize(void)
    {
    intxasp,yasp;/*用於讀x和y方向縱橫比*/
    GraphDriver=DETECT;/*自動檢測顯示器*/
    initgraph(&GraphDriver,&GraphMode,"");
    /*初始化圖形系統*/
    ErrorCode=graphresult();/*讀初始化結果*/
    if(ErrorCode!=grOk)/*如果初始化時出現錯誤*/
    {
    printf("GraphicsSystemError:%s ",
    grapherrormsg(ErrorCode));/*顯示錯誤代碼*/
    exit(1);/*退出*/
    }
    getpalette(&palette);/*讀面板信息*/
    MaxColors=getmaxcolor()+1;/*讀取顏色的最大值*/
    MaxX=getmaxx();/*讀屏幕尺寸*/
    MaxY=getmaxy();/*讀屏幕尺寸*/
    getaspectratio(&xasp,&yasp);/*拷貝縱橫比到變數中*/
    AspectRatio=(double)xasp/(double)yasp;/*計算縱橫比值*/
    }
    /*計算器函數*/
    voidcomputer(void)
    {
    structviewporttypevp;/*定義視口類型變數*/
    intcolor,height,width;
    intx,y,x0,y0,i,j,v,m,n,act,flag=1;
    floatnum1=0,num2=0,result;/*操作數和計算結果變數*/
    charcnum[5],str2[20]={""},c,temp[20]={""};
    charstr1[]="1230.456+-789*/Qc=^%";/*定義字元串在按鈕圖形上顯示的符號*/
    mwindow("Calculator");/*顯示主窗口*/
    color=7;/*設置灰顏色值*/
    getviewsettings(&vp);/*讀取當前窗口的大小*/
    width=(vp.right+1)/10;/*設置按鈕寬度*/
    height=(vp.bottom-10)/10;/*設置按鈕高度*/
    x=width/2;/*設置x的坐標值*/
    y=height/2;/*設置y的坐標值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(x+width*2,y,x+7*width,y+height);
    /*畫一個二維矩形條顯示運算數和結果*/
    setcolor(color+3);/*設置淡綠顏色邊框線*/
    rectangle(x+width*2,y,x+7*width,y+height);
    /*畫一個矩形邊框線*/
    setcolor(RED);/*設置顏色為紅色*/
    outtextxy(x+3*width,y+height/2,"0.");/*輸出字元串"0."*/
    x=2*width-width/2;/*設置x的坐標值*/
    y=2*height+height/2;/*設置y的坐標值*/
    for(j=0;j<4;++j)/*畫按鈕*/
    {
    for(i=0;i<5;++i)
    {
    setfillstyle(SOLID_FILL,color);
    setcolor(RED);
    bar(x,y,x+width,y+height);/*畫一個矩形條*/
    rectangle(x,y,x+width,y+height);
    sprintf(str2,"%c",str1[j*5+i]);
    /*將字元保存到str2中*/
    outtextxy(x+(width/2),y+height/2,str2);
    x=x+width+(width/2);/*移動列坐標*/
    }
    y+=(height/2)*3;/*移動行坐標*/
    x=2*width-width/2;/*復位列坐標*/
    }
    x0=2*width;
    y0=3*height;
    x=x0;
    y=y0;
    gotoxy(x,y);/*移動游標到x,y位置*/
    arrow();/*顯示游標*/
    putimage(x,y,rar,XOR_PUT);
    m=0;
    n=0;
    strcpy(str2,"");/*設置str2為空串*/
    while((v=specialkey())!=45)/*當壓下Alt+x鍵結束程序,否則執行下面的循環*/
    {
    while((v=specialkey())!=ENTER)/*當壓下鍵不是回車時*/
    {
    putimage(x,y,rar,XOR_PUT);/*顯示游標圖象*/
    if(v==RIGHT)/*右移箭頭時新位置計算*/
    if(x>=x0+6*width)
    /*如果右移,移到尾,則移動到最左邊字元位置*/
    {
    x=x0;
    m=0;
    }
    else
    {
    x=x+width+width/2;
    m++;
    }/*否則,右移到下一個字元位置*/
    if(v==LEFT)/*左移箭頭時新位置計算*/
    if(x<=x0)
    {
    x=x0+6*width;
    m=4;
    }/*如果移到頭,再左移,則移動到最右邊字元位置*/
    else
    {
    x=x-width-width/2;
    m--;
    }/*否則,左移到前一個字元位置*/
    if(v==UP)/*上移箭頭時新位置計算*/
    if(y<=y0)
    {
    y=y0+4*height+height/2;
    n=3;
    }/*如果移到頭,再上移,則移動到最下邊字元位置*/
    else
    {
    y=y-height-height/2;
    n--;
    }/*否則,移到上邊一個字元位置*/
    if(v==DOWN)/*下移箭頭時新位置計算*/
    if(y>=7*height)
    {
    y=y0;
    n=0;
    }/*如果移到尾,再下移,則移動到最上邊字元位置*/
    else
    {
    y=y+height+height/2;
    n++;
    }/*否則,移到下邊一個字元位置*/
    putimage(x,y,rar,XOR_PUT);/*在新的位置顯示游標箭頭*/
    }
    c=str1[n*5+m];/*將字元保存到變數c中*/
    if(isdigit(c)||c=='.')/*判斷是否是數字或小數點*/
    {
    if(flag==-1)/*如果標志為-1,表明為負數*/
    {
    strcpy(str2,"-");/*將負號連接到字元串中*/
    flag=1;
    }/*將標志值恢復為1*/
    sprintf(temp,"%c",c);/*將字元保存到字元串變數temp中*/
    strcat(str2,temp);/*將temp中的字元串連接到str2中*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,str2);/*顯示字元串*/
    }
    if(c=='+')
    {
    num1=atof(str2);/*將第一個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=1;/*做計算加法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='-')
    {
    if(strcmp(str2,"")==0)/*如果str2為空,說明是負號,而不是減號*/
    flag=-1;/*設置負數標志*/
    else
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=2;/*做計算減法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    }
    if(c=='*')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=3;/*做計算乘法標志值*/
    setfillstyle(SOLID_FILL,color+3);bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='/')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=4;/*做計算除法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='^')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=5;/*做計算乘方標志值*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='%')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=6;/*做計算模運算乘方標志值*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='=')
    {
    num2=atof(str2);/*將第二個操作數轉換為浮點數*/
    switch(act)/*根據運算符號計算*/
    {
    case1:result=num1+num2;break;/*做加法*/
    case2:result=num1-num2;break;/*做減法*/
    case3:result=num1*num2;break;/*做乘法*/
    case4:result=num1/num2;break;/*做除法*/
    case5:result=pow(num1,num2);break;/*做x的y次方*/
    case6:result=fmod(num1,num2);break;/*做模運算*/
    }
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*覆蓋結果區*/
    sprintf(temp,"%f",result);/*將結果保存到temp中*/
    outtextxy(5*width,height,temp);/*顯示結果*/
    }
    if(c=='c')
    {
    num1=0;/*將兩個操作數復位0,符號標志為1*/
    num2=0;
    flag=1;
    strcpy(str2,"");/*將str2清空*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*覆蓋結果區*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='Q')exit(0);/*如果選擇了q回車,結束計算程序*/
    }
    putimage(x,y,rar,XOR_PUT);/*在退出之前消去游標箭頭*/
    return;/*返回*/
    }
    /*窗口函數*/
    voidmwindow(char*header)
    {
    intheight;
    cleardevice();/*清除圖形屏幕*/
    setcolor(MaxColors-1);/*設置當前顏色為白色*/
    setviewport(20,20,MaxX/2,MaxY/2,1);/*設置視口大小*/
    height=textheight("H");/*讀取基本文本大小*/
    settextstyle(DEFAULT_FONT,HORIZ_DIR,1);/*設置文本樣式*/
    settextjustify(CENTER_TEXT,TOP_TEXT);/*設置字元排列方式*/
    outtextxy(MaxX/4,2,header);/*輸出標題*/
    setviewport(20,20+height+4,MaxX/2+4,MaxY/2+20,1);/*設置視口大小*/
    drawboder();/*畫邊框*/
    }
    voiddrawboder(void)/*畫邊框*/
    {
    structviewporttypevp;/*定義視口類型變數*/
    setcolor(MaxColors-1);/*設置當前顏色為白色*/
    setlinestyle(SOLID_LINE,0,NORM_WIDTH);/*設置畫線方式*/
    getviewsettings(&vp);/*將當前視口信息裝入vp所指的結構中*/
    rectangle(0,0,vp.right-vp.left,vp.bottom-vp.top);/*畫矩形邊框*/
    }
    /*設計滑鼠圖形函數*/
    intarrow()
    {
    intsize;
    intraw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4};/*定義多邊形坐標*/
    setfillstyle(SOLID_FILL,2);/*設置填充模式*/
    fillpoly(8,raw);/*畫出一游標箭頭*/
    size=imagesize(4,4,16,16);/*測試圖象大小*/
    rar=malloc(size);/*分配內存區域*/
    getimage(4,4,16,16,rar);/*存放游標箭頭圖象*/
    putimage(4,4,rar,XOR_PUT);/*消去游標箭頭圖象*/
    return0;
    }
    /*按鍵函數*/
    intspecialkey(void)
    {
    intkey;
    while(bioskey(1)==0);/*等待鍵盤輸入*/
    key=bioskey(0);/*鍵盤輸入*/
    key=key&0xff?key&0xff:key>>8;/*只取特殊鍵的掃描值,其餘為0*/
    return(key);/*返回鍵值*/
    }

❽ 怎樣用鏈表解決一元多項式的求導問題,求代碼

一元多項式求導,首先用鏈表存儲的話,每個結點應該對應一項的系數和指數,另外要有一個next指針指向下一項的結點,計算的時候遍歷鏈表對每一項按倒數計算方式計算就可以了,代碼可以參考以下網址別人的回答http://..com/question/77802626.html

❾ 一元多項式求導 什麼意思

幾元是指未知數的個數,一元就是一個未知數。多項式比如x^2+x+1就是一元二次三項式,至於求導就是求切線方程,有求導公式的,上面那個式子求導就是2x+1

❿ c語言 多項式求導

#include<stdio.h> #include<stdlib.h> typedef struct polynode { int conf;/*常數*/ int exp;/*指數*/ struct polynode *next; }polynode; int main() { polynode *p,*q,*h; /*建立多項式*/ int conf,exp; h=(polynode*)malloc(sizeof(polynode)); q=h; scanf("%d %d",&conf,&exp); while(conf!=-1||exp!=-1) { p=(polynode*)malloc(sizeof(polynode)); p->conf=conf; p->exp=exp; q->next=p; q=p; scanf("%d %d",&conf,&exp); } q->next=NULL; \\你是這里寫錯了,寫成NUll了 q=h; while(q->next!=NULL) /*求導*/ { q=q->next; if(q->exp>=1) { q->conf=(q->conf)*(q->exp); q->exp-=1; } else if(q->exp==0) { q=NULL; } else { printf("error"); break; } } q=h; while(q->next!=NULL)/*輸出*/ { q=q->next; printf("%d %d",q->conf,q->exp); } return 0; } 改成這樣就能運行了