习题3-6,进制转换1

来源:互联网 发布:婴幼儿棉裤淘宝 编辑:程序博客网 时间:2024/05/16 04:34

输入基数b,(2<=b<=10)和正整数n(十进制),输出n的b进制表示。

#include <cstdlib>#include <iostream>using namespace std;const int MAXN=100;int p[MAXN];int main(int argc, char *argv[]){    int b=10,n=0,m=0;    scanf("%d%d",&b,&n);    while( n!=0 )    {           p[m++]=n%b;           n/=b;    }    for( int i = m-1 ; i >= 0 ; --i)    {         printf("%d",p[i]);    }    system("pause");    return EXIT_SUCCESS;}


原创粉丝点击