填空题:请补充函数,该函数的功能是:输出一个N*N矩阵,要求非对对角线上的元素赋值0,对角线元素赋值1。
仅在横线上填入所编写的若干表达式或语句,勿改动函数中的内容。
#include
#define N 10
main()
{
int bb[N][N];
int i, j, n;
printf(" \nInput n:\n");
scanf("%d", &n);
for (i=0; i for (j=0; j {
___1___;
if (i == j)
bb[i][j] = ___2___;
if (___3___)
bb[i][j] = 1;
}
printf(" \n***** the result ******* \n");
for (i=0; i {
printf(" \n\n");
for (j=0; j printf("M", bb[i][j]);
}
}
填空题答案:
bb[i][j]=0
1
j==n-1-i或j==n-i-1 [NextPage] 改错题:下列给定程序中,fun函数的功能是:传入一个整数m,计算如下公式的值。
t=1-1/2-1/3-…-1/m
例如,若输入5,则应输入-0.283333。
请改正函数fun中的错误或在横线处填上适当的内容并把横线删除,使它能计算出正确的结果。
注意:不要改动main函数,不得增行或减行,也不得更改程序的结构。
#include
#include
double fun(int m)
{
double t = 1.0;
int i;
/********found********/
for (i=2; i<=m; i++)
t = 1.0 - 1/i;
/********found********/
___填空___
}
main()
{
int m;
printf("\nPlease enter 1 integer numbers:\n");
scanf("%d", &m);
printf("\n\nThe result is %lf\n", fun(m));
}
改错题答案:
t-=1.0/I;或t=t-1.0/i
return t;[NextPage] 编程题:假定输入的字符串中只包含字母和*号。请编写函数,它的功能是:除了字符串前导和尾部的*号之外,将串中其他*号全部删除。形参已指向字符串中第一个字母,形参已指向字符串中最后一个字母。在编写函数时,不得使用C语言提供的字符串函数。
例如,若字符串中的内容为****A*BC*DEF*G********,删除后,字符串中的内容则应当是****ABCDEFG********。在编写函数时,不得使用C语言提供的字符串函数。
请勿改动主函数和其他函数中的内容,仅在函数的花括号中填入所编写的若干语句。
#include
#include
#include
void fun( char *a, char *h, char *p)
{
}
main()
{
char s[81],*t,*f;
FILE *out;
printf("Enter a string:\n");
gets(s);
t=f=s;
while(*t)
t++;
t--;
while(*t=='*')
t--;
while(*f=='*')
f++;
fun(s,f,t);
printf("The string after deleted:\n");
puts(s);
out=fopen ("out.dat", "w");
strcpy(s, "****A*BC*DEF*G********");
fun(s, s+4, s+13);
fprintf(out, "%s", s);
fclose (out );
}
编程题答案:
void fun(char *a,char *h,char *p)
{
int i=0;
char *q=a;
while(q {
a[i]=*q;
q++;
i++:
}
while(q {
if(*q!=’*’)
{a[i]=*q;
i++;
}
q++;
}
while(*q)
{
a[i]=*q;
i++;
q++
}
a[i]=’\0’;
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|