C语言编程 自定义两个两位数的整数合并函数:

编写函数 fun,实现功能为
将两个两位数的整数 a、b 合并成一个整数放在 c 中。合并的方
式是:将 a 的十位和个位数依次放在 c 数千位和十位上,b 数的
十位和个位数依次放在 c 数的个位和百位上。
例如:当 a=45,b=12 时,调用函数后,c=4251

首先假设合并函数的功能:将两个两位数的整数 a、b 合并成一个整数放在 c 中。合并的方
式是:将 a 的十位和个位数依次放在 c 数千位和十位上,b 数的十位和个位数依次放在 c 数的个位和百位上。

实现方法如下:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-22
#include <stdio.h>
int fun(int a,int b)
{
int c;
c=(a/10)*1000+(b/10)*100+(a%10)*10+b%10;
return c;
}

void main()
{
int a,b;
printf("请输入两个两位数:");
scanf("%d%d",&a,&b);
printf("%d",fun(a,b));
}

我想问问题分不够了 感觉行的话给点分 谢谢本回答被提问者采纳
第2个回答  2009-11-21
这个挺简单的啊,
int fun(int a,int b)
{
int x,y,z,k;//分别代表千位、百位、十位、个位
int c;
x=a/10;
z=a%10;
k=b/10;
y=b%10;
c=x*1000+y*100+z*10+k;
return c;
}
第3个回答  2009-11-21
#include<stdio.h>
int fun(int a,int b)
{ int c;
c=a/10*1000+b%10*100+a%10*10+b/10;
return c;
}
void main()
{ int x,y,z;
printf("Please input two integer(double-digit)!\n");
scanf("%d,%d",&x,&y);
if(x<10||y<10||x>100||y>100)
printf("Error data!\n");
else
{ z=fun(x,y);
printf("the data after conformitying is %d\n",z);
}
}
相似回答