#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int zhan(char t)
{
int a;
char s[3]="";
int b;
if(isdigit(t))
{
b=t-'0';
a=0+b;
}
else
{
b=t-'a';
a=10+b;
}
return a;
}
char zhuan(int t)
{
char c;
if(t>=0&&t<=9)
{
c=t+'0';
}
else
{
c='a'+t-10;
}
return c;
}
int main()
{
int n;
char ch;
int b;
int c;
int flag=0;
int len1;
int len2;
int len3;
int i;
int j1;
int j2;
char s[1000];
char s1[1000];
char s2[1000];
char s3[1000]="";
int d[1000]={0};
scanf("%d",&n);
scanf("%s",s);
scanf("%s",s1);
len1=strlen(s);
len2=strlen(s1);
if(len1>len2)
{
len3=len1;
len1=len2;
len2=len3;
strcpy(s2,s);
strcpy(s,s1);
strcpy(s1,s2);
}
for(i=0;i<len1;i++)
{
b=zhan(s[len1-1-i]);
c= zhan(s1[len2-1-i]);
d[i]=(flag+(b+c))%n;
flag=(flag+(b+c))/n;
}
for(i=len1;i<len2;i++)
{
b=zhan(s1[len2-1-i]);
c=0;
d[i]=(flag+(b+c))%n;
flag=(flag+(b+c))/n;
}
if(flag!=0)
{
d[i]=flag;
for(i=0;i<len2+1;i++)
{
s3[i]=zhuan(d[len2+1-1-i]);
}
}
else
{
for(i=0;i<len2;i++)
{
s3[i]=zhuan(d[len2-1-i]);
}
}
printf("%s",s3);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
两个n(2~35)进制的求和输出用的和用n进制表示
共17个文件
manifest:2个
pdb:2个
htm:1个
5星 · 超过95%的资源 需积分: 28 12 下载量 77 浏览量
2014-06-14
14:27:42
上传
评论 1
收藏 292KB ZIP 举报
温馨提示
两个N进制的数求和的程序 , 第一行输入一个n进制的整数 第二行输入一个字符串(字符串代表的是一个N进制所表示的数) 第二行输入另外一个字符串 输出这两个和用这个n进制表示
资源推荐
资源详情
资源评论
收起资源包目录
zhoulr.zip (17个子文件)
zhoulr
zhoulr
main.c 1KB
zhoulr.vcproj.lenovo-PC.zlj.user 1KB
zhoulr.vcproj 4KB
Debug
zhoulr.exe.embed.manifest 663B
zhoulr.exe.intermediate.manifest 621B
zhoulr.exe.embed.manifest.res 728B
BuildLog.htm 4KB
vc90.pdb 60KB
main.obj 9KB
vc90.idb 35KB
mt.dep 60B
zhoulr.sln 884B
zhoulr.suo 10KB
zhoulr.ncb 571KB
Debug
zhoulr.pdb 395KB
zhoulr.exe 28KB
zhoulr.ilk 320KB
共 17 条
- 1
资源评论
- MonkeyDWade32014-10-09太好了, 终于找到了
zlj1991
- 粉丝: 2
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功