注意:部分源程序存在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的莅括号中填入你编写的若干语句。
请编写函数fun(),其功能是:将s所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
例如,当s所指字符串中的内容为ABCDEFGHIJK,则在t所指数组中的内容应是BDFHJ。
注意:部分源程序给出如下。
请勿改动主函数main口其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio .h>
include<string.h>
void fun(char *s,char t[])
{
}
main ()
char s[l00] ,t[l00];
clrscr ();
printf("%nPlease enter string S: ");
scanf("%s ",s);
fun(s,t);
prlntf("\nThe result is:%s\n ",t);
}
例如,一维数组中的数据是:2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10。
删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
请补充函数fun(),该函数的功能是:求100(不包括100)以内能被2或5整除,但不能同时被2和5整除的自然数。结果保存在数组bb中,函数fun()返回数组比元素的个数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 100
int fun (int bb [] )
{
int i, j;
for(【 】;i<100; i++)
if ((i%1!=0&&i%5==0)|| (i%2==0&&i%5 !=0)
【 】;
【 】;
}
main()
{
int i, n;
int bb [N];
clrscr ();
n=fun (bb);
for(i=0; i<n; i++)
{
if (i%10==0)
printf ("\n");
printf ("% 4d", bb [i]);
}
}
请编一个函数int fun(float s[ ],int n),它的功能是:求高于平均分的人数,并作为函数值返回。数组s中存放n位学生的成绩。数组s的值由主函数从键盘读入,用-1来结束输入。
请补充函数fun(),该函数的功能是:把字符下标为非素数的字符从字符串sb中删除,把字符下标为素数的字符重新保存在字符串e口中。字符串sb从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdefghijkl”,输出“cdfhl”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char s[],int n)
{
int i, j, k, flag;
【 】;
for(i=0; i<n; i++)
{
if (i>1)
s [k++] =s [i];
flag=I;
for(【 】; j<i&&flag; j++)
if (i%j==0)
{
flag=0;
【 】
}
}
s [k]='\0';
}
main()
{
int i=0, strlen=0;
char str[N];
clrscr ();
printf("\n Input a string:\n");
gets (str);
while (str [i] !='\0')
{
strlen++;
i++;
}
fun (str, strlen);
printf("\n*** display string ***\n");
puts (str);
}
请补充函数fun(),该函数的功能是:输出一个N×N矩阵,N由键盘输入,矩阵元素的值为随机数,并计算出该矩阵四周边元素的平均值,结果由函数返回。例如:当N=4时:
注章:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序;
include<stdio.h>
include<conio.h>
include<stdlib.h>
define N 20
double fun(int a[ ][N],int n)
{
int i,j;
int k;
double s=0.0;
double aver=0.0;
printf("*****The array*****\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=rand()%10;
printf("%4d",a[i][j]);
if(【 】)
s+=a[i][j];
}
printf("\n");
}
k=【 】;
aver=【 】;
return aver;
}
main()
{
int a[N][N];
int n;
double S;
Clrscr();
printf("*****Input the dimension Of array N*****\n");
scanf(“%d”,&n);
S=fun(a,n);
printf(“***** THE RESULT *****\n”);
printf(“The average is %2,3f\n”,S);
}
请补充函数fun(),该函数的功能是:按行统计N×N维矩阵元素中的最大值(均为整数),并把这些值按从小到大的顺序保存在数组b中。矩阵的维数在主函数中输入,并赋予随机数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
include<stdlib.h>
define N 20
void fun(【 】)
{
int i j;
int t;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(【 】)
b[i]=a[i][j];
for(i=0;i<n;i++)
{
for(j=0;i<n;j++)
if(【 】)
{
t=b[i];
b[i]=b[j];
b[j]=t;
}
}
}
main()
{
int a[N][N];
int b[N];
int n;
int i,j;
clrscr();
printf("*****Input the dimension of array N*****\n");
scanf("%d",&n);
printf("*****The array *****\n");
for(i=0;i<n;i++)
{
for(j=0;i<n;j++)
{
a[i][j]=rand()%20;
while(a[i][j]==0)
a[i][j]=rand()%30;
printf("%4d",a[i][j]);
}
printf(”\n\n”);
}
for(i=0;i<n;i++)
b[i]=0;
fun(a,b,n);
printf("***** THE RESULT *****\n");
for(i=0;i<n;i++)
printf(“%d”,b[i]);
}