计算机二级C语言上机考试编程题及答案1

全国等级考试资料网 2019-01-23 14:14:56 87
编程题
请编写函数fun,其功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的百位和个位上,b数的十位和个位数依次放在c数的十位和千位上。
例如,当a=45,b=12,调用该函数后,c=2415。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
void fun (int a, int b, long *c )
{
}
main ()
{
int a, b;  考试大论坛
long c;
FILE *out ;
printf ("Input a, b;");
scanf ("%d%d", &a, &b);
fun (a, b, &c);
printf ("The result is : %ld ", c);
out=fopen ("out.dat","w");
for (a = 20; a < 50; a+=3)
{
fun(a, 109-a, &c);
fprintf(out, "%ld ", c);
}
fclose (out );
}
参考答案:
void fun (int a, int b, long *c)
{
*c=(b%10)1000+(a/10)*100+(b/10)*10+a%10;
} 相关资料

相关阅读