求改错:用C语言把任意进制转化成十进制的算法,检验二进制的有时候有问题。代码如下。看project1就可以
#include<stdio.h>#include<stdlib.h>#include<math.h>voidproject1();voidproject2();intx...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void project1();
void project2();
int x;
int y;
int a;
int b;
int main(int argc, char *argv[])
{
printf("1.十进制转化为任意进制;\n");
printf("2.任意进制转化成十进制;\n");
printf("3.退出\n");
while(x!=3)
{
printf("请选择服务序号:\n");
scanf("%d",&x);
if(x==1)
project1();
else if(x==2)
project2();
else if(x==3)
break;
else
printf("输入不符合规范,请重新输入\n");
}
system("PAUSE");
return 0;
}
void project1()
{
printf("请输入进制数:\n");
scanf("%d",&y);
int num1;
int num2=0;
int s=0;
int i=0;
printf("请输入一个数:");
scanf("%d",&num1);
while(num1>0)
{
s = num1 % y;
num2 = s*pow(10,i) + num2;
num1 = (num1-s)/y;
i++;
}
printf("转化成%d进制后为:%d\n",y,num2);
return ;
}
void project2()
{
printf("请输入进制数:\n");
scanf("%d",&y);
int num1,num2=0;
int s,i;
i=0;
printf("请输入一个数:");
scanf("%d",&num1);
while(num1>0)
{
num2=(num1%10)*pow(y,i)+num2;
num1=num1/10;
i++;
}
printf("转化成十进制后为:%d\n",num2);
return ;
} 展开
#include <stdlib.h>
#include <math.h>
void project1();
void project2();
int x;
int y;
int a;
int b;
int main(int argc, char *argv[])
{
printf("1.十进制转化为任意进制;\n");
printf("2.任意进制转化成十进制;\n");
printf("3.退出\n");
while(x!=3)
{
printf("请选择服务序号:\n");
scanf("%d",&x);
if(x==1)
project1();
else if(x==2)
project2();
else if(x==3)
break;
else
printf("输入不符合规范,请重新输入\n");
}
system("PAUSE");
return 0;
}
void project1()
{
printf("请输入进制数:\n");
scanf("%d",&y);
int num1;
int num2=0;
int s=0;
int i=0;
printf("请输入一个数:");
scanf("%d",&num1);
while(num1>0)
{
s = num1 % y;
num2 = s*pow(10,i) + num2;
num1 = (num1-s)/y;
i++;
}
printf("转化成%d进制后为:%d\n",y,num2);
return ;
}
void project2()
{
printf("请输入进制数:\n");
scanf("%d",&y);
int num1,num2=0;
int s,i;
i=0;
printf("请输入一个数:");
scanf("%d",&num1);
while(num1>0)
{
num2=(num1%10)*pow(y,i)+num2;
num1=num1/10;
i++;
}
printf("转化成十进制后为:%d\n",num2);
return ;
} 展开
2个回答
2011-11-26
展开全部
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_binaryStringToHexString(char *strBinary,char *strHex);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024];
icePub_binaryStringToHexString("1001110001101",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_binaryStringToIntegerString(char *strBinary,char *strInteger);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024];
icePub_binaryStringToIntegerString("1001110001101",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_integerStringToBinaryString(char *strInteger,char *strBinary);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024*8];
icePub_integerStringToBinaryString("12345678443901234567",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_hexStringToBinaryString(char *strHex,char *strBinary);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024*8];
icePub_hexStringToBinaryString("A1B2C3D4E5F87654321A",strResult);
AfxMessageBox(strResult);
{
__declspec(dllexport)
int WINAPI icePub_binaryStringToHexString(char *strBinary,char *strHex);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024];
icePub_binaryStringToHexString("1001110001101",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_binaryStringToIntegerString(char *strBinary,char *strInteger);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024];
icePub_binaryStringToIntegerString("1001110001101",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_integerStringToBinaryString(char *strInteger,char *strBinary);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024*8];
icePub_integerStringToBinaryString("12345678443901234567",strResult);
AfxMessageBox(strResult);
extern "C"
{
__declspec(dllexport)
int WINAPI icePub_hexStringToBinaryString(char *strHex,char *strBinary);
}
#pragma comment(lib,"icePubDll.lib")
char strResult[1024*8];
icePub_hexStringToBinaryString("A1B2C3D4E5F87654321A",strResult);
AfxMessageBox(strResult);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我测试的都通过了啊 ,你是什么错误?
追问
我测试十进制下的4转化成二进制,结果输出99
追答
?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询