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

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

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

编程题:

15.请编写一个函数unsigned fun(unsigned  w),w是一个大于10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后n-1位的数作为函数值返回。

例如:w值为5923,则函数返回923;若w值为923,则函数返回23。

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

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

#include <conio.h>

#include <stdio.h>

unsigned fun ( unsigned w )

{

 

}

 

main( )

{

unsigned x;

clrscr( );

printf ( “Enter a unsigned integer number :  ” );

scanf ( “%u”, &x );

printf ( “The original data is :  %un”, x );

if ( x<10 )

printf (“Data error !”);

else

printf ( “The result  :  %un”, fun ( x ) );

}

 

19.编写函数fun,该函数的功能是:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。

例如:若程序执行时输入字符串为:turbo c and borland c++,从键盘上输入字符n,则输出后变为:turbo c ad borlad c++;如果输入的字符在字符串中不存在,则字符串照原样输出。

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

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

若干语句。

#include <stdio.h>

#include <conio.h>

int fun(char s[],int c)

{

}

main()

{

static char str[]=”turbo c and borland c++”;

char ch;

clrscr();

printf(“原始字符串:%sn”,str);

printf(“输入一个字符:”);

scanf(“%c”,&ch);

fun(str,ch);

printf(“str[]=%sn”,str);

}

 

改错题:

30.下列给定程序中函数fun的功能是:计算正整数num的各位上的数字之积。例如,若输入252,则输出应该是20。若输入202,则输出应该是0。

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

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

试题程序:

#include<stdio.h>

#include<conio.h>

long fun(long num)

{

long k;

do

{

k*=num%10;

num=10;

} while(num);

return(k);

}

main()

{

long n;

clrscr();

printf(“please enter a number:”);

scanf(“%ld”,&n);

printf(“n%ldn”,fun(n));

}

 

 

31.下列给定程序中,函数fun的功能是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入“Ab,cD”,则输出“AB,CD”。

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

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

试题程序:

#include <conio.h>

#include <stdio.h>

#include <string.h>

char *fun(char tt[])

{

int i;

for(i=0;tt[i];i++)

if((‘a'<=tt[i])||(tt[i]<=’z’))

tt[i]+=32;

return(tt);

}

main()

{

int i;

char tt[81];

clrscr();

printf(“nPlease enter a string:”);

gets(tt);

printf(“nThe result string is :n%s”,fun(tt));

}

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

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

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