C语言程序设计习题补充资料(标准答案).doc
文本预览下载声明
C语言程序设计补充资料--答案
第1章 C 语言程序设计上机习题
1.
(1) for (i=0; it1;i++)
(2) for (j=0; js1;j++)
(3) *u=’\0’;
2..
(1) void fun (char *s, char *t)
(2) t[2*d] = \0;
3..
(1) switch(*s );
(2) for( i = 0; i 5; i++ )
4 .
(1) while ( *w )
(2) if ( *r == *p ) { r++; p++; }
5 .
(1) float fun( int k )
(2) return s;
6.
(1) void fun(char *str, char ch )
(2) if ( *str ! = ch )
(3) str[1] = \0
7. 参考程序
fun ( char *s )
{int i, length;
length=strlen(s);
for (i=0; ilength;i++ )
{ if ((( s[i]=a ) (s[i]=y))|| (( s[i]=A ) (s[i]=Y)))
s[i]=s[i]+1;
if(s[i]==Z)s[i]=A;
if(s[i]==z)s[i]=a;}}
8. 参考程序
void fun(int a[], int b[], int c[], int n)
{int i, j;
for(i=0, j=n-1; i5; i++,j--)
c[i]=a[i]-b[j];}
9. 参考程序
void fun(char *s, char t[])
{int i=0,j;
char *p;
p=s;
for(j=0;j100;j++)
{ if (*s==\0){t[i]=\0;break;}
if ((j%2==0)||(*s%2==0))
{ t[i]=*s;
i++;
}
s++;
}
}
10. 参考程序
char *EXUL( char tt[ ] )
{ char *p=tt
for(;*tt;tt++ )
if ((*tt=A) (*tt=Z))
*tt =A-a;
return p;}
第3章 C 语言上机考试样卷
一、程序调试
1.
(1) scanf (“%d”,n),n=0
(2) t=t*2
2..
(1) float *x[],int m,int n
(2) a[i]
3..
(1) m=0||n=0
(2) k=m
4 .
(1) m=m-1
(2) f(x,n)
5 .
(1) while(n0)
(2) n=n/10
6.
(1) m=m/10
(2) return –y;
7.
(1) return 1
(2) f(a,b,c,u1,u2)
8..
(1) t=a[0]
(2) j=1;jn;j++
9..
(1) int i
(2) i==1
12 .
(1) y=x[0]
(2) f(b,5,-1)
13.
(1) m=0||n=0
(2) k=k+m
二、程序设计题
1. 参考程序 ??
{ x=(a+b+c)/2;
s=sqrt(x*(x-a)*(x-b)*(x-c));
2. 参考程序
p=fopen(design.dat,w);
while (*a!=’\0’)
{s=s+*a; a++;}
fprintf(p,%d,s);
fclose(p);
3. 参考程序
p=fopen(design.dat,w);
for(x=1;x=sqrt(2000);x++)
for(y=1;y=sqrt(2000);y++)
for(z=1;z=sqrt(2000);z++)
if(x*x+y*y+z*z)==2000)
k++;
fprintf(p,%d, k);
fclose(p);
4. 参考程序
FILE *p; int x=0;
p=fopen(design.dat,w);
do{
x++; }
while( !(x%3==1 x%5==3 x%7==5 x%9==7);
fprintf(p,%d,x);
fclose(p);
5. 参考程序
p=fopen(design.dat,w);
for( i=2;i=12;i++)
{ k=k*i;
s=s+k; }
fprintf(p,%d,s);
fclose(p);
6. 参考程序
p=fopen(design.dat,w);
for( i=0;i10;i++)
if( ( (x[i]-1)* (x[i]-1)+ (y[i]+0.5)* (y[i
显示全部