2015-09-21 06:30:02
阅读( 128 )
编程题:
15.请编写一个函数unsigned fun(unsigned w),w是一个大于10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后n-1位的数作为函数值返回。
例如:w值为5923,则函数返回923;若w值为923,则函数返回23。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
unsigned fun ( unsigned w )
{
}
main( )
{
unsigned x;
clrscr( );
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 ) );
}
19.编写函数fun,该函数的功能是:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。
例如:若程序执行时输入字符串为:turbo c and borland c++,从键盘上输入字符n,则输出后变为:turbo c ad borlad c++;如果输入的字符在字符串中不存在,则字符串照原样输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的
若干语句。
#include
#include
int fun(char s[],int c)
{
}
main()
{
static char str[]=”turbo c and borland c++”;
char ch;
clrscr();
printf(“原始字符串:%s\n”,str);
printf(“输入一个字符:”);
scanf(“%c”,&ch);
fun(str,ch);
printf(“str[]=%s\n”,str);
}
改错题:
30.下列给定程序中函数fun的功能是:计算正整数num的各位上的数字之积。例如,若输入252,则输出应该是20。若输入202,则输出应该是0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
long fun(long num)
{
/********found********/
long k;
do
{
k*=num%10;
/********found********/
num\=10;
} while(num);
return(k);
}
main()
{
long n;
clrscr();
printf(“\please enter a number:”);
scanf(“%ld”,&n);
printf(“\n%ld\n”,fun(n));
}
31.下列给定程序中,函数fun的功能是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入“Ab,cD”,则输出“AB,CD”。
请改正程序中的错误,使它能统计出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
#include
char *fun(char tt[])
{
int i;
/********found********/
for(i=0;tt[i];i++)
if((‘a’<=tt[i])||(tt[i]<=’z'))
/********found********/
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));
}
分享给朋友:
亲~ 如果您有更好的答案 可在评论区发表您独到的见解。
您想查看更多的信息:
面试题