栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

C语言编程笔试题(第十二套)

C语言编程笔试题(第十二套)

编程题:

38.请编写函数fun,它的功能是:求出ss所指字符串中指定字符的个数,并返回此值。

例如,若输入字符串123412132,输入字符1,则输出3。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <conio.h>

#include <stdio.h>

#define  M 81

int fun(char *ss, char c)

{

 

}

 

main()

{

char  a[M],  ch;

clrscr();

printf(“nPlease enter a string:”);

gets(a);

printf(“nPlease enter a char:”);

ch = getchar();

printf(“nThe number of the char is: %dn”, fun(a, ch));

}

 

39.请编写函数fun,该函数的功能是:移动一维数组中的内容;若数组中有n个整数,要求把下标从0到p(p小于等于n-1)的数组元素平移到数组的最后。

例如,一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10;p的值为3。移动后,一维数组中的内容应为:5,6,7,8,9,10,1,2,3,4。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <stdio.h>

#define    N    80

void fun(int *w,int p,int n)

{

 

}

main()

{

int  a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

int  i,p,n=15;

printf(“The original data:n”);

for(i=0; i<n; i++)

printf(“%3d”,a[i]);

printf(“nnEnter  p:  “);

scanf(“%d”,&p);

fun(a,p,n);

printf(“nThe data after moving :n”);

for(i=0; i<n; i++)

printf(“%3d”,a[i]);

printf(“nn”);

}

 

改错题:

74.下列给定程序中,函数fun的功能是:利用插入排序法对字符串中的字符按从小到

大的顺序进行排序。插入法的基本算法是:先对字符串中的头两个元素进行排序。然后把第三个字符插入到前两个字符中,插入后前三个字符依然有序;再把第四个字符插入到前三个字符中,……。待排序的字符串已在主函数中赋予。

请改正程序中的错误,使它能得出正确结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#define  N  80

#include “stdio.h”

#include “string.h”

void insert(char *aa)

{

int i,j,n;

char ch;

n=strlen(aa);

for(i=1; i<n ;i++ )

{

c=aa[i];

j=i-1;

while ((j>=0) && (ch<aa[j] ))

{

aa[j+1]=aa[j];

j–;

}

aa[j+1]=ch;

}

}

main( )

{

char a[N]=”QWERTYUIOPASDFGHJKLMNBVCXZ”;

int  i;

printf(“The original string :     %sn”,a);

insert(a);

printf(“The string after sorting :  %snn”,a);

}

 

 

79.下列给定程序中函数fun的功能是:删除字符串s中的所有空白字符(包括Tab字符、回车符及换行符)。输入字符串时用“#”结束输入。

请改正程序中的错误,使它能输出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <string.h>

#include <stdio.h>

#include <ctype.h>

 

void fun(char *p)

{

int i,t;

char c[80];

for(i=0,t=0;p[i];i++)

if(!isspace(*(p+i)))

c[t++]=p[i];

c[t]=””;

strcpy(p,c);

}

 

main( )

{

char c,s[80];

int i=0;

printf(“Input a string: “);

c=getchar();

while(c!=’#’)

{

s[i]=c;

i++;

c=getchar();

}

s[i]=’’;

fun(s);

puts(s);

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265387.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号