.填空题
请补充main函数,该函数的功能是:把一个字符串中的所有小写字母字符全部转换成大写字母字符,其他字符不变,结果保存原来的字符串中。
例如:当str[N]="123 abcdef ABCDEF!",结果输出:"123 ABCDEF ABCDEF!"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 80
void main()
{
int j;
char str[N]=" 123abcdef ABCDEF!";
char *pf=str;
system("CLS");
printf("***original string ***/n");
puts(str);
【1】;
while(*(pf+j))
{
if(*(pf+j)>='a'&&*(pf+j)<='z')
{
*(pf+j)=【2】;
j++;
}
else
【3】;
}
printf("******new string******/n");
puts(str);
system("pause");
}
1. 改错题
下列给定程序中,函数fun()的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <string.h>
void fun(char *p,char *q,char *c)
{ int k=0;
while(*p||*q)
/**********************found***********************/
{ if (*p<=*q)
c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++ ;
/**********************found***********************/
k++
}
}
请补充main函数,该函数的功能是:把一个字符串中的所有小写字母字符全部转换成大写字母字符,其他字符不变,结果保存原来的字符串中。
例如:当str[N]="123 abcdef ABCDEF!",结果输出:"123 ABCDEF ABCDEF!"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 80
void main()
{
int j;
char str[N]=" 123abcdef ABCDEF!";
char *pf=str;
system("CLS");
printf("***original string ***/n");
puts(str);
【1】;
while(*(pf+j))
{
if(*(pf+j)>='a'&&*(pf+j)<='z')
{
*(pf+j)=【2】;
j++;
}
else
【3】;
}
printf("******new string******/n");
puts(str);
system("pause");
}
1. 改错题
下列给定程序中,函数fun()的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <string.h>
void fun(char *p,char *q,char *c)
{ int k=0;
while(*p||*q)
/**********************found***********************/
{ if (*p<=*q)
c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++ ;
/**********************found***********************/
k++
}
}
void main()
{ char a[10]="fshADfg",b[10]="sdAEdi",c[80]={'/0'};
fun(a,b,c);
printf("The string a:"); puts(a);
printf("The string b:"); puts(b);
printf("The result :"); puts(c);
}
{ char a[10]="fshADfg",b[10]="sdAEdi",c[80]={'/0'};
fun(a,b,c);
printf("The string a:"); puts(a);
printf("The string b:"); puts(b);
printf("The result :"); puts(c);
}
1. 编程题
请编写函数fun,其功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数个位和十位上,b数的十位和个位数依次放在c数的百位和千位上。
例如,当a=16,b=35,调用该函数后,c=5361。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdlid.h>
#include<stdio.h>
void fun(int a ,int b,long *c)
{
请编写函数fun,其功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数个位和十位上,b数的十位和个位数依次放在c数的百位和千位上。
例如,当a=16,b=35,调用该函数后,c=5361。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdlid.h>
#include<stdio.h>
void fun(int a ,int b,long *c)
{
}
void main()
{
int a,b;
long c;
system("CLS");
printf("Input a,b;");
scanf("%d%d",&a, &b);
fun(a,b,&c);
printf("The result is:%ld/n",c);
}
2.填空题
请补充main函数,该函数的功能是求方程ax2+bx+c=0的两个实数根。方程的系数a、b、c从键盘输入,如果判别式(disc=b2-4ac)小于0,则要求重新输入a、b、c的值。
例如,当a=1,b=2,c=1时,方程的两个根分别是x1=-1.00, x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
float a,b,c, disc,x1,x2;
system("CLS");
do
{
printf("Input a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)
printf("disc=%f/n Input again!
/n",disc);
}while(【1】);
printf("*******the result*******/n");
x1=【2】;
x2=【3】;
printf("/nx1=%6.2f/nx2=%6.2f/n",x1,x2);
}
请补充main函数,该函数的功能是求方程ax2+bx+c=0的两个实数根。方程的系数a、b、c从键盘输入,如果判别式(disc=b2-4ac)小于0,则要求重新输入a、b、c的值。
例如,当a=1,b=2,c=1时,方程的两个根分别是x1=-1.00, x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
float a,b,c, disc,x1,x2;
system("CLS");
do
{
printf("Input a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)
printf("disc=%f/n Input again!
/n",disc);
}while(【1】);
printf("*******the result*******/n");
x1=【2】;
x2=【3】;
printf("/nx1=%6.2f/nx2=%6.2f/n",x1,x2);
}
2. 改错题
下列给定程序中,函数fun()的功能是根据整型形参m,计算如下公式的值。
y=1-1/(2×2)+1/(3×3)-1/(4×4)+…+(-1)(m+1)/(m×m)
例如:m中的值为5,则应输出0.838611。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
double fun(int m)
{ double y=1.0;
/**********************found***********************/
int j=1;
int i;
for(i=2; i<=m; i++)
{
j=-1*j;
/**********************found***********************/
y+=1/(i * i);
}
return(y);
}
下列给定程序中,函数fun()的功能是根据整型形参m,计算如下公式的值。
y=1-1/(2×2)+1/(3×3)-1/(4×4)+…+(-1)(m+1)/(m×m)
例如:m中的值为5,则应输出0.838611。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
double fun(int m)
{ double y=1.0;
/**********************found***********************/
int j=1;
int i;
for(i=2; i<=m; i++)
{
j=-1*j;
/**********************found***********************/
y+=1/(i * i);
}
return(y);
}
void main()
{
int n=5;
system("CLS");
printf("/nThe result is %lf/n" ,fun(n));
}
{
int n=5;
system("CLS");
printf("/nThe result is %lf/n" ,fun(n));
}
2. 编程题
请编一个函数void fun(int tt[M][N], int pp[N]), tt指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入pp所指的一维数组中。二维数组中的数已在主函数中给出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#define M 3
#define N 4
void fun(int tt[M][N],int pp[N])
{
请编一个函数void fun(int tt[M][N], int pp[N]), tt指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入pp所指的一维数组中。二维数组中的数已在主函数中给出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#define M 3
#define N 4
void fun(int tt[M][N],int pp[N])
{
}
void main()
{
int t[M][N]={{68, 32, 54, 12},{14, 24, 88, 58},{42, 22, 44, 56}};
int p[N],i,j,k;
system("CLS");
printf("The riginal data is:/n");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
printf("%6d",t[i][j]);
printf("/n");
}
fun(t,p);
printf("/nThe result is:/n");
for(k=0;k<N;k++)
printf("%4d",p[k]);
printf("/n");
}
3.填空题
请补充函数fun(),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如:当n=13572468时,str="86427531"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define N 80
char str[N];
void fun(long int n)
{
int i=0;
while(【1】)
{
str[i]=【2】;
n/=10;
i++;
}
【3】;
}
void main()
{
long int n=13572468;
system("CLS");
printf("*** the origial data ***/n");
printf("n=%ld",n);
fun(n);
printf("/n%s",str);
}
3. 改错题
下列给定程序中,函数fun的功能是按以下递归公式求函数值。
例如:当给n输入5时,函数值为240;当给n输入3时,函数值为60。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
/**********************found***********************/
fun(int n);
{
int c;
/**********************found***********************/
请补充函数fun(),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如:当n=13572468时,str="86427531"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define N 80
char str[N];
void fun(long int n)
{
int i=0;
while(【1】)
{
str[i]=【2】;
n/=10;
i++;
}
【3】;
}
void main()
{
long int n=13572468;
system("CLS");
printf("*** the origial data ***/n");
printf("n=%ld",n);
fun(n);
printf("/n%s",str);
}
3. 改错题
下列给定程序中,函数fun的功能是按以下递归公式求函数值。
例如:当给n输入5时,函数值为240;当给n输入3时,函数值为60。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
/**********************found***********************/
fun(int n);
{
int c;
/**********************found***********************/
if(n=1)
c=15;
else
c=fun(n-1)*2;
return(c);
}
c=15;
else
c=fun(n-1)*2;
return(c);
}
void main()
{
int n;
printf("Enter n:");
scanf("%d",&n);
printf("The result :%d/n/n",fun(n));
}
3. 编程题
请编写函数fun(),对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII值码升序排列。
编写完程序,运行程序后输入:字符串为Bdsihad,则排序后输出为应为Badhisd。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void fun(char *s, int num)
{
{
int n;
printf("Enter n:");
scanf("%d",&n);
printf("The result :%d/n/n",fun(n));
}
3. 编程题
请编写函数fun(),对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII值码升序排列。
编写完程序,运行程序后输入:字符串为Bdsihad,则排序后输出为应为Badhisd。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void fun(char *s, int num)
{
}
void main()
{
char s[10];
system("CLS");
printf("输入7个字符的字符串:");
gets(s);
fun(s,7);
printf("/n%s",s);
}
void main()
{
char s[10];
system("CLS");
printf("输入7个字符的字符串:");
gets(s);
fun(s,7);
printf("/n%s",s);
}
4.填空题
数组xx[N]保存着一组3位数的无符号正整数,其元素的个数通过变量num传入函数fun()。请补充函数fun(),该函数的功能是:从数组xx中找出个位和百位的数字相等的所有无符号整数,结果保存在数组yy中,其个数由函数fun()返回。
例如:当xx[8]={135,787,232,222,424,333,141,541}时,bb[6]={787,232,222,424,333,141}。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 1000
int fun(int xx[],int bb[],int num)
{
int i,n=0;
int g,b;
for(i=0;i<num;i++)
{
g=【1】;
b=xx[i]/100;
if(g==b)
【2】;
}
return【3】;
}
void main()
{
int xx[8]={135,787,232,222,424,333,
141,541};
int yy[N];
int num=0,n=0,i=0;
num=8;
system("CLS");
printf("***original data ***/n");
for(i=0;i<num;i++)
printf("%u ",xx[i]);
printf("/n/n/n");
n=fun(xx,yy,num);
printf("/nyy= ");
for(i=0;i<n;i++)
printf("%u ",yy[i]);
}
4. 改错题
下列给定程序中函数fun()的功能是计算1/n!的值。
例如:给n输入5,则输出0.008333。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
/**********************found***********************/
int fun(int n)
{ double result =1.0;
if(n==0)
return 1.0;
while(n>1 && n <170)
/**********************found***********************/
result *=n++ ;
result=1/result;
return result;
}
数组xx[N]保存着一组3位数的无符号正整数,其元素的个数通过变量num传入函数fun()。请补充函数fun(),该函数的功能是:从数组xx中找出个位和百位的数字相等的所有无符号整数,结果保存在数组yy中,其个数由函数fun()返回。
例如:当xx[8]={135,787,232,222,424,333,141,541}时,bb[6]={787,232,222,424,333,141}。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 1000
int fun(int xx[],int bb[],int num)
{
int i,n=0;
int g,b;
for(i=0;i<num;i++)
{
g=【1】;
b=xx[i]/100;
if(g==b)
【2】;
}
return【3】;
}
void main()
{
int xx[8]={135,787,232,222,424,333,
141,541};
int yy[N];
int num=0,n=0,i=0;
num=8;
system("CLS");
printf("***original data ***/n");
for(i=0;i<num;i++)
printf("%u ",xx[i]);
printf("/n/n/n");
n=fun(xx,yy,num);
printf("/nyy= ");
for(i=0;i<n;i++)
printf("%u ",yy[i]);
}
4. 改错题
下列给定程序中函数fun()的功能是计算1/n!的值。
例如:给n输入5,则输出0.008333。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
/**********************found***********************/
int fun(int n)
{ double result =1.0;
if(n==0)
return 1.0;
while(n>1 && n <170)
/**********************found***********************/
result *=n++ ;
result=1/result;
return result;
}
void main()
{
int n;
printf("Input N:");
scanf("%d",&n);
printf("/n1/%d!=%lf/n",n,fun(n));
}
4. 编程题
编写函数fun(),它的功能是求n以内(不包括n)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。
例如:n为1000时,函数值应为s=96.979379。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
double fun(int n)
{
{
int n;
printf("Input N:");
scanf("%d",&n);
printf("/n1/%d!=%lf/n",n,fun(n));
}
4. 编程题
编写函数fun(),它的功能是求n以内(不包括n)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。
例如:n为1000时,函数值应为s=96.979379。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
double fun(int n)
{
}
void main()
{
system("CLS");
printf("s=%f/n", fun(1000));
}
5.填空题
请补充main函数,该函数的功能是求方程ax2+bx+c=0的根(方程的系数a,b,c从键盘输入)。
例如,当a=1,b=2,c=1时,方程的两个根分别是:x1=-1.00,x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,disc,x1,x2,p,q;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
system("CLS");
printf("*******the result *******/n");
if(disc>=0)
{
x1=【1】;
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%6.2f,x2=%6.2f/n",x1,x2);
}
else
{
p=【2】;
q=【3】;
printf("x1=%6.2f+%6.2f i/n",p,q);
printf("x2=%6.2f-%6.2f i/n",p,q);
}
}
5. 改错题
下列给定程序中函数fun()的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
long fun(long num)
{
/**********************found***********************/
{
system("CLS");
printf("s=%f/n", fun(1000));
}
5.填空题
请补充main函数,该函数的功能是求方程ax2+bx+c=0的根(方程的系数a,b,c从键盘输入)。
例如,当a=1,b=2,c=1时,方程的两个根分别是:x1=-1.00,x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,disc,x1,x2,p,q;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
system("CLS");
printf("*******the result *******/n");
if(disc>=0)
{
x1=【1】;
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%6.2f,x2=%6.2f/n",x1,x2);
}
else
{
p=【2】;
q=【3】;
printf("x1=%6.2f+%6.2f i/n",p,q);
printf("x2=%6.2f-%6.2f i/n",p,q);
}
}
5. 改错题
下列给定程序中函数fun()的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
long fun(long num)
{
/**********************found***********************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/**********************found***********************/
}while(num)
return (k);
}
do
{
k+=(num%10)*(num%10);
num/=10;
/**********************found***********************/
}while(num)
return (k);
}
void main()
{
long n;
system("CLS");
printf("Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
5. 编程题
请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时 ,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
int fun(int t)
{
{
long n;
system("CLS");
printf("Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
5. 编程题
请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时 ,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
int fun(int t)
{
}
void main()
{
int n;
system("CLS");
n=1000;
printf("n=%d, f=%d/n",n, fun(n));
}
6.填空题
请补充函数fun(),该函数的功能是:计算N×N维矩阵元素的方差,结果由函数返回。维数N在主函数中输入。例如:
的计算结果是14.414
求方差的公式为:
其中
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define N 20
double fun(【1】,int n)
{
int i,j;
double s=0.0;
double f=0.0;
double aver=0.0;
double sd=0.0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
s+=a[i][j];
aver=【2】;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
f+=(a[i][j]-aver)*(a[i][j]-aver);
f/=(n*n);
sd=【3】;
return sd;
}
void main()
{
int a[N][N];
int n;
int i,j;
double s;
system("CLS");
printf("***** Input the dimension of
array N*****/n");
scanf("%d",&n);
printf("***** The array *****/n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=rand()%50;
while(a[i][j]==0)
a[i][j]=rand()%60;
printf("%4d",a[i][j]);
}
printf("/n/n");
}
s=fun(a,n);
printf("***** THE RESULT *****/n");
printf(" %4.3f/n",s);
}
6. 改错题
下列给定程序中,函数fun()的功能是将字符串s中位于偶数位置的字符或ASCII码为奇数的字符放入字符串t中(规定第一个字符放在第0位中)。
例如:字符串中的数据为ADFESHDI,则输出应当是AFESDI。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#define N 80
/**********************found***********************/
void fun(char s, char t[ ])
{
int i, j=0;
for(i=0; i<strlen(s);i++)
/**********************found***********************/
{
int i, j=0;
for(i=0; i<strlen(s);i++)
/**********************found***********************/
if(i%2=0||s[i]%2!=0)
t[j++]=s[i] ;
t[j]='/0';
}
t[j++]=s[i] ;
t[j]='/0';
}
void main()
{
char s[N], t[N];
system("CLS");
printf("/nPlease enter string s :");
gets(s);
fun(s,t);
printf("/nThe result is :%s/n",t);
}
6. 编程题
请编写一个函数fun(),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)的平方和(规定n的值不大于100)。
例如:主函数从键盘给输入n的值为56,则输出为sum=1113。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
long fun(int n)
{
{
char s[N], t[N];
system("CLS");
printf("/nPlease enter string s :");
gets(s);
fun(s,t);
printf("/nThe result is :%s/n",t);
}
6. 编程题
请编写一个函数fun(),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)的平方和(规定n的值不大于100)。
例如:主函数从键盘给输入n的值为56,则输出为sum=1113。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
long fun(int n)
{
}
void main()
{
int n;
long sum;
printf("Input n:");
scanf("%d", &n);
sum=fun(n);
printf("sum=%ld/n", sum);
}
7.填空题
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1="How do",str2="?od uoy",结果输出:"How do you do?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define N 40
void fun(char *str1,char *str2)
{
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n=【1】;
for(;k<=j/2;k++,j--)
{
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
}
【2】;
for(;【3】;i++)
*(p1+i)=*p2++;
*(p1+i)='/0';
}
void main()
{
char str1[N],str2[N];
system("CLS");
printf("***Input the string str1 & str2
***/n");
printf("/nstr1:");
gets(str1);
printf("/nstr2:");
gets(str2);
printf("*** The string str1 & str2 ***/n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*** The new string ***/n");
puts(str1);
}
{
int n;
long sum;
printf("Input n:");
scanf("%d", &n);
sum=fun(n);
printf("sum=%ld/n", sum);
}
7.填空题
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1="How do",str2="?od uoy",结果输出:"How do you do?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define N 40
void fun(char *str1,char *str2)
{
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n=【1】;
for(;k<=j/2;k++,j--)
{
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
}
【2】;
for(;【3】;i++)
*(p1+i)=*p2++;
*(p1+i)='/0';
}
void main()
{
char str1[N],str2[N];
system("CLS");
printf("***Input the string str1 & str2
***/n");
printf("/nstr1:");
gets(str1);
printf("/nstr2:");
gets(str2);
printf("*** The string str1 & str2 ***/n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*** The new string ***/n");
puts(str1);
}
7. 改错题
下列给定程序中,函数fun()的功能是找出100~n(不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#define N 100
int fun(int *s, int n)
{
int i,j,k,a,b,c;
j=0;
for(i=100; i<n; i++)
{
/**********************found***********************/
下列给定程序中,函数fun()的功能是找出100~n(不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#define N 100
int fun(int *s, int n)
{
int i,j,k,a,b,c;
j=0;
for(i=100; i<n; i++)
{
/**********************found***********************/
k=n;
a=k%10;
k/=10;
b=k%10;
c=k/10;
if(a==b+c)
/**********************found***********************/
a=k%10;
k/=10;
b=k%10;
c=k/10;
if(a==b+c)
/**********************found***********************/
s[j]=i;
}
return j;
}
}
return j;
}
void main()
{
int a[N], n,num=0, i;
do
{
printf("/nEnter n(<=1000) :");
scanf("%d",&n);
}
while(n > 1000);
num= fun(a,n);
printf("/n/nThe result :/n");
for(i=0; i<num; i++)
printf("%5d",a[i]);
printf("/n/n");
}
{
int a[N], n,num=0, i;
do
{
printf("/nEnter n(<=1000) :");
scanf("%d",&n);
}
while(n > 1000);
num= fun(a,n);
printf("/n/nThe result :/n");
for(i=0; i<num; i++)
printf("%5d",a[i]);
printf("/n/n");
}
7. 编程题
程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[ ][ N ],int n),该函数的功能是使数组左下半三角元素中的值加上n。
例如:若n的值为3,a数组中的值为
a=2 5 4
1 6 9
5 3 7
则返回主程序后a数组中的值应为
5 5 4
4 9 9
8 6 10
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define N 5
fun(int a[ ][N], int n)
{
程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[ ][ N ],int n),该函数的功能是使数组左下半三角元素中的值加上n。
例如:若n的值为3,a数组中的值为
a=2 5 4
1 6 9
5 3 7
则返回主程序后a数组中的值应为
5 5 4
4 9 9
8 6 10
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define N 5
fun(int a[ ][N], int n)
{
}
void main()
{
int a[N][N],n, i,j;
system("CLS");
printf("***** The array *****/n");
for(i=0; i<N; i++) /*产生一个随机5*5矩阵*/
{
for(j=0; j<N; j++)
{
a[i][j]=rand()%10;
printf("%4d", a[i][j]);
}
printf("/n");
}
do
n=rand()%10; /*产生一个小于5的随机数n*/
while(n>=5);
printf("n=%4d/n",n);
fun(a, n);
printf("*****THE RESULT*****/n");
for(i=0; i<N; i++)
{
for (j=0; j<N; j++)
printf("%4d",a[i][j]);
printf("/n");
}
}
{
int a[N][N],n, i,j;
system("CLS");
printf("***** The array *****/n");
for(i=0; i<N; i++) /*产生一个随机5*5矩阵*/
{
for(j=0; j<N; j++)
{
a[i][j]=rand()%10;
printf("%4d", a[i][j]);
}
printf("/n");
}
do
n=rand()%10; /*产生一个小于5的随机数n*/
while(n>=5);
printf("n=%4d/n",n);
fun(a, n);
printf("*****THE RESULT*****/n");
for(i=0; i<N; i++)
{
for (j=0; j<N; j++)
printf("%4d",a[i][j]);
printf("/n");
}
}
8.填空题
请补充函数fun(),该函数的功能是:按'0'到'9'统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。
例如:输入"x=112385713.456+0.909*bc",结果为:1=3,3=2,5=2,7=1,9=2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define N 1000
void fun(char *tt,int num[])
{
int i,j;
int bb[10];
char *p=tt;
for(i=0;i<10;i++)
{
num[i]=0;
bb[i]=0;
}
while(【1】)
{
if(*p>='0'&&*p<='9')
【2】;
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
【3】;
}
void main()
{
char str[N];
int num[10],k;
system("CLS");
printf("/nPlease enter a char string:");
gets(str);
printf("/n**The original string**/n");
puts(str);
fun(str,num);
printf("/n**The number of letter**/n");
for(k=0;k<5;k++)
{
printf("/n");
printf("%d=%d",2*k+1,num[k]);
}
printf("/n");
}
请补充函数fun(),该函数的功能是:按'0'到'9'统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。
例如:输入"x=112385713.456+0.909*bc",结果为:1=3,3=2,5=2,7=1,9=2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define N 1000
void fun(char *tt,int num[])
{
int i,j;
int bb[10];
char *p=tt;
for(i=0;i<10;i++)
{
num[i]=0;
bb[i]=0;
}
while(【1】)
{
if(*p>='0'&&*p<='9')
【2】;
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
【3】;
}
void main()
{
char str[N];
int num[10],k;
system("CLS");
printf("/nPlease enter a char string:");
gets(str);
printf("/n**The original string**/n");
puts(str);
fun(str,num);
printf("/n**The number of letter**/n");
for(k=0;k<5;k++)
{
printf("/n");
printf("%d=%d",2*k+1,num[k]);
}
printf("/n");
}
8. 改错题
下列给定程序中,函数fun()的功能是求出数组中最小数和次最小数,并把最小数和a[0]中的数对调,次最小数和a[1]中的数对调。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <sydlib.h>
#include <conio.h>
#include <stdio.h>
#define N 20
void fun(int *a,int n)
{
int i, m, t, k;
/**********************found***********************/
下列给定程序中,函数fun()的功能是求出数组中最小数和次最小数,并把最小数和a[0]中的数对调,次最小数和a[1]中的数对调。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <sydlib.h>
#include <conio.h>
#include <stdio.h>
#define N 20
void fun(int *a,int n)
{
int i, m, t, k;
/**********************found***********************/
for(i=0; i<n; i++)
{
m=i;
for(k=i; k<n; k++)
if(a[k]<a[m])
/**********************found***********************/
k=m;
t=a[i];
a[i]=a[m];
a[m]=t;
}
}
{
m=i;
for(k=i; k<n; k++)
if(a[k]<a[m])
/**********************found***********************/
k=m;
t=a[i];
a[i]=a[m];
a[m]=t;
}
}
void main()
{
int b[N]={11,5,12,0,3,6,9,7,10,8},n=10,i;
system("CLS");
for(i=0; i<n; i++)
printf("%d ",b[i]);
printf("/n");
fun(b,n);
for(i=0; i<n; i++)
printf("%d ", b[i]);
printf("/n");
}
{
int b[N]={11,5,12,0,3,6,9,7,10,8},n=10,i;
system("CLS");
for(i=0; i<n; i++)
printf("%d ",b[i]);
printf("/n");
fun(b,n);
for(i=0; i<n; i++)
printf("%d ", b[i]);
printf("/n");
}
8. 编程题
m个人的成绩存放在score数组中,请编写函数fun(),它的功能是:将高于平均分的人数作为函数值返回,将高于平均分的分数放在up所指的数组中。
例如,当score数组中的数据为24,35,88,76,90,54,59,66,96时,函数返回的人数应该是5,up中的数据应为88,76,90,66,96。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(int score[],int m, int up[])
{
m个人的成绩存放在score数组中,请编写函数fun(),它的功能是:将高于平均分的人数作为函数值返回,将高于平均分的分数放在up所指的数组中。
例如,当score数组中的数据为24,35,88,76,90,54,59,66,96时,函数返回的人数应该是5,up中的数据应为88,76,90,66,96。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(int score[],int m, int up[])
{
}
void main()
{
int i, n, up[9];
int score[9]={24,35,88,76,90,54,59,66,96};
system("CLS");
n=fun(score, 9, up);
printf("/nup to the average score are: ");
for(i=0;i<n;i++)
printf("%d ",up[i]);
}
9.填空题
请补充main函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组b中并输出,把其他字符保存在b[10]中。
例如:当str1="ab123456789cde090"时,结果为:
0:2 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:2 other charactor:5
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int i,b[11];
char *str="ab123456789cde090";
char *p=str;
system("CLS");
printf("*** the origial data ***/n");
puts(str);
for(i=0;i<11;i++)
b[i]=0;
while(*p)
{
switch(【1】)
{
case '0':b[0]++;break;
case '1':b[1]++;break;
case '2':b[2]++;break;
case '3':b[3]++;break;
case '4':b[4]++;break;
case '5':b[5]++;break;
case '6':b[6]++;break;
case '7':b[7]++;break;
case '8':b[8]++;break;
case '9':b[9]++;break;
【2】
}
【3】
}
printf("****** the result ********/n");
for(i=0;i<10;i++)
printf("/n%d:%d",i,b[i]);
printf("/nother charactor:%d",b[i]);
}
请补充main函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组b中并输出,把其他字符保存在b[10]中。
例如:当str1="ab123456789cde090"时,结果为:
0:2 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:2 other charactor:5
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int i,b[11];
char *str="ab123456789cde090";
char *p=str;
system("CLS");
printf("*** the origial data ***/n");
puts(str);
for(i=0;i<11;i++)
b[i]=0;
while(*p)
{
switch(【1】)
{
case '0':b[0]++;break;
case '1':b[1]++;break;
case '2':b[2]++;break;
case '3':b[3]++;break;
case '4':b[4]++;break;
case '5':b[5]++;break;
case '6':b[6]++;break;
case '7':b[7]++;break;
case '8':b[8]++;break;
case '9':b[9]++;break;
【2】
}
【3】
}
printf("****** the result ********/n");
for(i=0;i<10;i++)
printf("/n%d:%d",i,b[i]);
printf("/nother charactor:%d",b[i]);
}
9. 改错题
下列给定程序中,函数fun()的功能是计算并输出high以内的素数之和。high由主函数传给fun()函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
下列给定程序中,函数fun()的功能是计算并输出high以内的素数之和。high由主函数传给fun()函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found***********************/
{
yes=0;
break;
}
/**********************found***********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
{
sum+=high;
n++;
}
high--;
}
return sum;
}
void main()
{
system("CLS");
printf("%d/n",fun(100));
}
{
system("CLS");
printf("%d/n",fun(100));
}
9. 编程题
请编写函数void fun (int x, int pp[], int *n),它的功能是:求出能整除x且不是奇数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为24,则有6个数符合要求,它们是2,4,6,8,12,24。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
请编写函数void fun (int x, int pp[], int *n),它的功能是:求出能整除x且不是奇数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为24,则有6个数符合要求,它们是2,4,6,8,12,24。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
void fun (int x, int pp[], int *n)
{
{
}
void main ()
{
int x,aa[1000], n, i ;
system("CLS") ;
printf("/nPlease enter an integer number : /n ") ;
scanf ("%d", &x) ;
fun (x, aa, &n) ;
for (i=0 ; i<n ; i++)
printf ("%d ", aa [i]);
printf ("/n ") ;
}
{
int x,aa[1000], n, i ;
system("CLS") ;
printf("/nPlease enter an integer number : /n ") ;
scanf ("%d", &x) ;
fun (x, aa, &n) ;
for (i=0 ; i<n ; i++)
printf ("%d ", aa [i]);
printf ("/n ") ;
}