将两个两位数的正整数a,b合并成一个整数放在c中,合并的方式

将两个两位数的正整数a,b合并成一个整数放在c中,合并的方式
请各位帮忙写你个小程序,将两个两位数的正整数a,b合并成一个整数放在c中,合并的方式;
将a数的十位和个位放在c的千位和十位上,b数的十位和个位数依次放c的个位和百位上如当a=45,b=12时c=4251
主函数已经给了,帮我编一下子函数,
#include
#include
#include
void fun(int a,int b,long *c)
{
}
main()
{ int a,b;long c;
system("cls");
printf("Input a,b:");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("The result is:%ld\n",c);
其他人气:647 ℃时间:2020-06-19 13:21:08
优质解答
#include
#include
#include
void fun(int a,int b,long *c)
{
int a1,a2,b1,b2; /*分别存放a数十位,a数个位,b数十位,b数个位的数字*/
a1 = a/10;
a2 = a%10;
b1 = b/10;
b2 = b%10;
*c = a1 * 1000 + b2 * 100 + a2 * 10 + b1; /*数字按要求组合,存入c*/
}
main()
{
int a,b;
long c=0;
system("cls");
printf("Input a,b:");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("The result is:%ld\n",c);
return 0;
}
vc++ 6.0 成功运行
我来回答
类似推荐
请使用1024x768 IE6.0或更高版本浏览器浏览本站点,以保证最佳阅读效果。本页提供作业小助手,一起搜作业以及作业好帮手最新版!
版权所有 CopyRight © 2012-2024 作业小助手 All Rights Reserved. 手机版