例如,当n值为500时,各位数字之和为15的整数有:159、168、177、186、
195、249、258、267、276、285、294、339、348、357、366、375、384、393、
429、438、447、456、465、474、483、492。共有26个。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
int fun(int x)
{int n, s1, s2, s3, t;
/**********found**********/
n=__1__;
t=100;
/**********found**********/
while(t<=__2__)
{s1=t; s2=(t/10); s3=t/100;
if(s1+s2+s3==15)
{printf("%d ",t);
n++;
}
/**********found**********/
__3__;
}
return n;
}
main()
{int x=-1;
while(x>999||x<0)
{printf("Please input(0
printf("\nThe result is: %d\n",fun(x));
}
解题答案:
/**********found**********/
n=0;
/**********found**********/
while(t<=x)
/**********found**********/
t++;
****************************************** [NextPage] 改错题:给定程序MODI1.C中函数fun的功能是:先将s所指字符串中的字符按逆序存放到t所指字符串中,然后把s所指串中的字符按正序连接到t所指串的后面。
例如:当s所指的字符串为:"ABCDE"时,则t所指的字符串应为:"EDCBAABCDE"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
void fun (char *s, char *t)
{
/************found************/
int i;
sl = strlen(s);
for (i=0; i
/************found************/
t[i] = s[sl-i];
for (i=0; i
t[sl+i] = s[i];
t[2*sl] = '\0';
}
main()
{char s[100], t[100];
printf("\nPlease enter string s:"); scanf("%s", s);
fun(s, t);
printf("The result is: %s\n", t);
}
解题答案:
/************found************/
int i,sl;
/************found************/
t[i]=s[sl-i-1];
******************************************
[NextPage] 程序题:函数fun的功能是: 将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的百位和个位上,b中的十位和个位数依次放在变量c的千位和十位上。
例如,当a=45,b=12。调用该函数后,c=1425。
注意: 部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun(int a, int b, long *c)
{
}
main() /* 主函数 */
{int a,b; long c;void NONO ();
printf("Input a, b:");
scanf("%d%d", &a, &b);
fun(a, b, &c);
printf("The result is: %ld\n", c);
NONO();
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
int i, a,b ; long c ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%d,%d", &a, &b);
fun(a, b, &c);
fprintf(wf, "a=%d,b=%d,c=%ld\n", a, b, c);
}
fclose(rf);
fclose(wf);
}
参考答案:
void fun(int a, int b, long *c)
{
*c=(b/10)*1000+(a/10)*100+(b)*10+(a);
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|