活动设计题 假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:删除字符串中所有的*号。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:ABCDEFG。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include <stdio.h>
void fun(char *a)
{
}
main()
{ char s[81];
printf('Enter a string:\n');gets(s);
fun(s);
printf('the string after deleted:\n');puts(s);
}
活动设计题 请编写函数proc(),其功能是:计算并输出下列多项式的值。
S=(1+1/2)+(1/3+1/4)+…+(1/(2n-1)+1/2n)
例如,若输入10,则输出为S=3.597740。
n的值要求大于1,但不大于100。
注意:部分源程序如下。
请勿改动函数main()和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
double proc(int n)
{
}
void main()
{
int n;
double s;
printf('\nInput n:');
scanf('%d',n);
s=proc(n);
printf('\ns=%f\n',s);
}
活动设计题 请编写函数fun,其功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入的字符串为“-1234”,则函数把它转换为整数值-1234。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若千语句。
试题程序:
#include<stdio.h>
#include<string.h>
long fun(char*p)
{
}
void main()
{
char s[6];
long n;
printf('Enter a string:\n');
gets(s);
n=fun(s);
printf('%ld\n',n);
}
活动设计题请编写函数fun,其功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为则字符串中的内容应是:WSHWSHWSHWSH。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#defineM3#defineN4voidfun(char(*s)[N],char*b){}voidmain(){chara[100],w[M][N]={{'W','W','W','W'},{'S','S','S','S'},{'H','H','H','H'}};inti,j;printf('Thematrix:\n');for(i=0;i<M;i++){for(j=0;j<N;j++)printf('%3c',w[i][j]);printf('\n');}fun(w,a);printf('TheAstrLng:\n');puts(a);printf('\n\n');}
活动设计题
请编写一个函数fun,它的功能是:求出1到m之间(含m)能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。例如,若传送给m的值为50,则程序输出:
7 11 14 21 22 28 33 35 42 44 49
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include<stdio.h>
#define M 100
void fun(int m, int *a, int *n)
{
}
main()
{ int aa[M], n, k;
void NONO();
fun(50, aa, n);
for(k=0; k<n; k++)
if((k+1)%20==0)printf('\n');
else printf('%4d', aa[k]);
printf('\n');
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *fp, *wf;
int i, n, j, k, aa[M], sum;
fp=fopen('in.dat', 'r');
wf=fopen('out.dat', 'w');
for(i=0; i<10; i++) {
fscanf(fp, '%d,', j);
fun(j, aa, n);
sum=0;
for(k=0; k<n; k++) sum+=aa[k];
fprintf(wf, '%d\n', sum);
}
fclose(fp);
fclose(wf);
}
活动设计题
函数fun的功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的百位和个位上,b中的十位和个位数依次放在变量c的千位和十位上。
例如,当a=45,b=12。调用该函数后,c=1425。
注意:部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(int a, int b, long *c)
{
}
main() /*主函数*/
{ int a, b; long c;
printf('Input a b:');
scanf('%d%',a, b);
fun(a, b, c);
printf('The result is:%ld\n', c);
}
活动设计题 编写程序,实现矩阵(3行3列)的转置f即行列互换)。
例如,输入下面的矩阵:
100 200 300
400 500 600
700 800 900
程序输出:
100 400 700
200 500 800
300 600 900
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(int array[3][3])
{
}
main()
{
int i, j;
int array[3][3]={{100, 200, 300},
{400, 500, 600},
{700, 800, 900}};
for(i=0; i<3; i++)
{ for(j=0; j<3; j++)
printf('%7d', array[i][j]);
printf('\n');
}
fun(array);
printf('Converted array:\n');
for(i=0; i<3; i++)
{ for(j=0; j<3; j++)
printf('%7d', array[i][j]);
printf('\n');
}
}
活动设计题 编写函数fun,w是一个大于10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后n-1位的数作为函数值返回。
例如,w值为5923,则函数返回923;若W值为923,则函数返回23。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
unsigned fun(unsigned w)
{
}
void main()
{
unsigned x;
system('CLS');
printf('Enter a unsigned integer number:');
scanf('%u',x);
printf('The original data is:%u\n',x);
if(x<10)
printf('Data error!');
else
printf('The result:%u\n',fun(x));
}
活动设计题程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(inta[][N],intn),函数的功能是:使数组左下三角元素中的值乘以n。例如:若n的值为3,a数组中的值为则返回主程序后a数组中的值应为请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#include<stdio.h>#include<stdlib.h>#defineN5voidfun(inta[][N],intn){}main(){inta[N][N],n,i,j;{a[il[j]=rand()%10;printf('\n');}don=rand()%10;while(n>=3);printf('n=%4d\n',n);fun(a,n);{for(j=0;j<N;j++)printf('%4d',a[i][j]);printf('\n');}}
活动设计题 请编写函数proc(),它的功能是计算下列级数和,和值由函数值返回。
sum=1-x+x2/2!-x3/3!+…+(-1*x)n/n!
例如,当n=23,x=0.3时,函数值为0.740818。
注意:部分源程序如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
double proc(double x,int n)
{
}
void main()
{
system('CLS');
printf('%f',proc(0.3,23));
}
活动设计题 编写函数fun,其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除指定字符后的字符串存放在b所指的数组中,n中存放指定的下标。
例如,输入一个字符串“World”,然后输入3,则调用该函数后的结果为“Word”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define LEN 20
void fun (char a[], char b[], int n)
{
}
void main()
{
char str1[LEN], str2[LEN];
int n;
system('CLS');
printf ('Enter the string:\n');
gets (str1);
printf ('Enter the position of the string deleted:');
scanf ('%d', n);
fun (str1. str2, n);
printf ('The new string is:% s\n', str2);
}
活动设计题 M名学生的成绩已在主函数中放入一个带头结点的链表结构中,h指向链表的带头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。
注意:部分源程序如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define M 8
struct slist
{ double s;
struct slist *next;
};
typedef struct slist STREC;
double proc(STREC *h)
{
}
STREC*creat(double *s)
{
STREC *h,*p,*q;
int i=0;
h=p=(STREC*)malloc(sizeof(STREC));
p->s=0;
while(i<M)
//产生8个结点的链表,各分数存入链表中
{
q=(STREC*)malloc(sizeof(STREC));
p->s=s[i];i++;p->next=q;p=q;
}
p->next=NULL;
return h;
//返回链表的首地址
}
void outlist(STREC *h)
{
STREC *p;
p=h;
printf('head');
do
{printf('->%2.0f',p->s);p=p->next;}
//输出各分数
while(p->next!=NULL);
printf('\n\n');
}
void main()
{
double stu[M]={56,89,76,95,91,68,75,
85},max;
STREC *h;
h=creat(stu);
outlist(h);
max=proc(h);
printf('max=%6.1f\n',max);
}
活动设计题请编写函数fun,其功能是:计算并输出当x<0.97时下列多项式的值,直到|Sn-Sn-1|<0.000001为止。例如,在主函数中从键盘给x输入0.21后,输出为:s=1.100000。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include<stdio.h>#include<math.h>doublefun(doublex){ }NONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/FILE*rf,*wf;inti;doubles,x;rf=fopen('in.dat','r')wf=fopen('out.dat','w');for(i=0;i<10;i++){fscanf(rf,'%lf',x);s=fun(x);fprintf(wf,'%lf\n',s);}fclose(rf);fclose(wf);}main(){doublex,s;printf('Inputx:');scanf('%lf',x);s=fun(x);printf('s=%f\n',s);NONO();}
活动设计题 请编写一个函数void fun (char a[], char b[], int n),其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除指定字符后的字符串存放在b所指的数组中,n中存放指定的下标。
例如,输入一个字符串:World,然后输入3,则调用该函数后的结果为:Word。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include <stdio.h>
#include <string.h>
#define LEN 20
void fun(char a[],char b[], int n)
{
}
main()
{ char str1[LEN], str2[LEN];
iiit n;
printf('Enter the string:\n');
gets(str1);
printf('Enter the index of the char deleted:');
scanf('%d',n);
fun(str1,str2,n);
printf('The new string is:%s\n', str2);
}
活动设计题 学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。请编写函数fun,其功能是:函数返回该学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是strcmp)。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#define N 16
typedef struct
{
char num[10];
int s;
}STREC;
STREC fun(STREC*a,char*b)
{
}
void main()
{
STREC s[N]={{GA005',85},
{'GA003',76},{'GA002',69},{'GA004',85},{'GA001',91},{'GA007',72},{'GA008',64},{'GA006',87},{'GA015',85},{'GA013',91},{'GA012',64},{'GA014',91},{'GA011',77},{GA017',64},{'GA018',64},{'GA016',72}};
STREC h;
char m[10];
int i;
printf('The original data:\n');
for(i=0;i<N;i++)
{
if(i%4==0)
printf('\n'); /*每行输出4个学生记录*/
printf('%s%3d',s[i]num,s[i].s);
}
printf('\n\nEnter the number:');
gets(m);
h=fun(s,m);
printf('The data:');
printf(”\n%s%4d\n',h.num,hs);
printf('\n');
}
活动设计题请编写函数fun,其功能是:计算并输出下列多项式的值。例如,在主函数中从键盘给n输入50后,输出为S=1.718282。注意:要求n的值在大于1但不大于100之间。部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>doublefun(intn){}main(){intn;doubles;printf('Inputn:');scanf('%d',n);s=fun(n);printf('S=%f',s);}
活动设计题 编写函数fun,其功能是:将s所指字符串中除了下标为奇数同时ASCII码值也为奇数的字符之外,其余的所有字符全部删除,串中剩余字符所形成的一个新串放在t所指的数组中。
例如,若s所指字符串的内容为“ABCDEFG12345”,其中字符A的ASCII码值为奇数,但所在元素的下标为偶数,因此需要删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指数组中的内容应为“135”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
void fun(char *s,char t[])
{
}
main()
{
char s[100],t[100];
printf('\nPlease enter string s:');
scanf('% s',s);
fun(s,t);
printf('\nThe result is:% s\n',t);
}
活动设计题 假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:将字符串尾部的*号全部删除,前面和中间的*号不删除。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:****A*BC*DEF*G。在编写函数时,不得使用C语言提供的字符串函数。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(char *a)
{
}
main()
{char s[81];
printf('Enter a slring:\n');gets(s);
fun(s);
printf('The string after deleted:\n');puts(s);
}
活动设计题 下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun,函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:
0 1 2 7 9
1 9 7 4 5
2 3 8 3 1
4 5 6 8 2
5 9 1 4 1
则返回主程序后s的值应为3.375。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 5
double fun (int w[][N])
{
}
void main()
{
int a[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};
int i,j;
double s;
system('CLS');
printf('*****The array*****\n');
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{printf('%4d',a[i][j]);}
printf('\n');
}
s=fun(a);
printf('****THE RESULT****\n');
printf('The sum is:%1f\n',s);
}
活动设计题 请编写函数proc(),该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。
例如,若字符串数组中的M个字符串为:
ABCD
BCDEFG
CDEFGHI
则合并后的字符串内容应该是ABCDBCDEFGCDEFGHI。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define M 3
#define N 20
void proc(char arr[M][N], char*b)
{
}
void main()
{
char str[M][N]={'ABCD', 'BCDEFG', 'CDEFGHI'}, i;
char arr[100]={'##################'};
printf('The string: \n');
for(i=0; i<M; i++)
puts(str[i]);
printf('\n');
proc(str,arr);
printf('The A string: \n');
printf('%s', arr);
printf('\n\n');
}
