n=n++;
if(t>=10)
{uu[n++]=t/10;uu[n]=t%10;}
elseuu[n]=t;
}
main()
{inti,n,aa[10]={0,0,0,0,0,0};
scanf("%d%d%d",&n,&aa[0],&aa[1]);
for(i=1;i
#include
floatf(floatx)
{returnx*(3*x*(x-1)+1)-1;}
floatf1(floatx)
{return9*x*x-6*x+1;}
floatnewtoon(floatx)
{floatf,f1,x0;
do
{;
f=f(x0);
f1=f1(x0);
x=;
}while(fabs(x-x0)>1e-5);
returnx;
}
main()
{floatx0;
scanf("%f,,&x0);
printf("theresult=%.2f\n",newtoon(x0));
}
17.設一個單向鏈表結點的數據類型定義為:
structnode
{intx;
structnode*next;
};
fun函數從h指向的鏈表第二個結點開始遍曆所有結點,當遇到x值為奇數的結點時,將該結點移到h鏈表第一個結點之前,函數返回鏈表首結點地址。print函數輸出p指向的鏈表中所有結點的x值。程序運行後的輸出結果是“1342”。
#include
#defineN4
structnode
{intx;
structnode*next;
};
voidprint(stmctnode*p)
{while()
{printf("%4d",);p=p->next;}
printf("\n");
}
structnode*fun(structnode*h)
{structnode*p1,*p2,*p3;
p1=h;p2=p1->next;
while(p2)
{if(p2->x%2)
{p3=p2;
p1->next=;
p2=p1->next:
p3->next=h;
;
}
else
{p1=p2;p2=p2->next;}
}
returnh;
}
main()
{structnodea[N]={{4},{3},{2},{1}},*head=a;inti,num;
for(i=0;i
Charsubs[80];
Char*cut(char*str,intloca,number)
{intk;
if(strlen(str)
main()
{inta;floatb;
scanf("%3d%f",&a,&b);
printf("%d\t%f",a,b);
}
若要求變量a和b分別從鍵盤獲得輸入值45和6780,則以下四種輸入數據中,不能達到該要求的輸入數據是()(凵代表空格,代表回車)
A.45凵678B.45678
C.45,678D.045678
5.已知有預處理命令#include和聲明“chars[10]="Thankyou";inti;”,要求輸出字符串“Thankyou”,以下選項中不能達到該要求的語句是()
A.puts(s);
B.printf("%s",s[10]);
C.for(i=0;s[i]!=\0;i++)printf("%c",s[i]);
D.for(i=0;s[i]!=\0;i++)putchar(s[i]);
6.下列程序段中,能將變量x、y中值較大的數保存到變量a,值較小的數保存到變量b的程序段是()
A.if(x>y)a=x;b=y;elsea=y;b=x;
B.if(x>y){a=x;b=y;}elsea=y;b=x;
C.if(x>y){a=x;b=y;}else{a=y;b=x;}
D.if(x>y){a=x;b=y;}else(xb);
C.puts(++x->b);D.puts((++p)->b);
二、填空題(每空2分,共計50分)
1.已知有聲明“intx=1,y=2,z=3;”,則執行語句x>y?(z-=--x):(z+=++x);後,變量x、z的值分別是。
2.循環語句中通常包含一個循環條件表達式,該表達式的值決定是否執行下一次循環。在C語言的循環語句中,循環條件表達式可缺省的語句是。
3.若一個函數不需要形式參數,則在定義該函數時,應該使形式參數表為空或放置一個。
4.已知有聲明“floatd=1;doublef=1;longg;”和語句printf("",g=10+i+(int)d*f);”,為了正確地以十進製形式輸出printf參數表中第二個參數(表達式)的值,則在第一個參數中的下劃線位置處應填寫的格式轉換說明符是。
5.設函數a的定義如下:
voida()
{intx=12,y=345;FILE*fp=fopen("my.dat","w");
fprintf(fp,"%d%d",x,y);
fclose(fp);
}
已知main函數中聲明了“intx,y;FILE*fp=fopen("my.dat","r");”,如果需要從文件my.dat中正確讀出由函數a寫入的兩個數據並分別保存到變量x和y中,則在main函數中使用的讀數據語句應當是(要求寫出語句的完整格式)。
6.以下程序運行時輸出的結果是。
#include
voidf(int*p,intn)
{intt;
t=*p;*p=*(p+n-1);*(p+n-1)=t;
}
voidmain()
{inta[5]={1,2,3,4,5},i;
f(&a[1],3);
for(i=0;i
fun(intx)
{if(x/2>0)fun(x/2);
printf("%d",x%2);
}
voidmain()
{fun(20);putchar(\n);
}
8.以下程序運行時,輸出的結果是。
#include
voidmain()
{inti,k,x[10]={1,2,3,4,5,6,7,8,9,10},y[3]={0};
for(i=0;i
voidmain()
{printf("%d",f(3));printf("\n%d",f(5));}
intf(inta)
{intb=1;staticintc=1;
b=b*a;c=c*a;
returnc/b;
}
10.以下程序運行時,輸出結果的第一行是,第二行是。
#include
voidf(int*x,inty)
{*x=y+1;y=*x+2;}
voidmain()
{inta=2,b=2;
f(&a,b);
printf("%d\n%d",a,b);
}
11.以下程序運行時,輸出結果的第一行是,第二行是。
#include
#include
typedefstructP
{charc;structP*next;}PNODE;
PNODE*create(charx[])
{inti;PNODE*pt,*pre,*p=0;
for(i=0;x[i]!=\0;i++)
{pt=(PNODE*)malloc(sizeof(PNODE));
pt->c=x[i];pt->next=NULL;
if(p==0){p=pt;pre=pt;}
else{pre->next=pt;pre=pre->next;}
}
returnp;
}
voidprint(PNODE*p)
{while(p){putchar(p->c);p=p->next;}
putchar(\n);
}
PNODE*joint(PNODE*pha,PNODE*phb)
{PNODE*pa=pha,*pb=phb,*pc=NULL,*pt,*pre;
while(pa)
{pb=phb;
while(pb)
{if(pa->c==pb->c)
{pt=(PNODE*)malloc(sizeof(PNODE));
pt->c=pa->c;pt->next=NULL;