四、程序填充題(本大題共3小題,每小題6分,共18分)
請將下列程序橫線處缺少的部分補上,使其能正確運行。
30.將數(shù)組a中元素按下圖循環(huán)左移一位并輸出。
a[0] a[1] a[2] a[3] a[4]
執(zhí)行前 |
1 |
2 |
3 |
4 |
5 |
執(zhí)行后 |
2 |
3 |
4 |
5 |
1 |
# include <stdio.h>
void main ( )
{ int j,k,a[5]={1,2,3,4,5};
k=a[0];
for(j=0;j<5;j++)
a[j]=______;/*第一空*/
a[4]=______;/*第二空*/
for ( j=0;j<5;j++)
printf (“%5d’’,_______);/*第三空*/
printf (“\n’’);
}
31.計算并輸出1!+2!+3!+4!+5!的值。
# include<stdio.h>
int f (int a)
{ static int c=1;
c=c*a;
return_____;/*第一空*/
}
void main ()
{ int i,k;
k=_________;/*第二空*/
for (i=2;i<=5;i++) k+=f(________);/*第三空*/
printf (“%d\n”,k);
}
32.將文本文件fin.dat中的數(shù)字字符找出并寫入文本文件fnum.dat中。
#include<stdio.h>
void main ()
{
char ch;FILE*fin,*fnum;
fin=fopen (“fin.dat”,________);/*第一空*/
fnum=fopen (“fnum.dat”,“w’’);
while(!feof(_______))/*第二空*/
{
ch=fgetc(fin);
if(______)fputc (ch,fnum);/*第三空*/
}
fclose (fin);
fclose(fnum);
}