新手请教,为什么下面程序得不到正确结果?
#include<iostream>using namespace std;
const int N=100;
void binary(int n)
{
int i=0,j,m,s[N];
cout<<"该十进制正整数转化为二进制为:";
for(i=0;n>0;i++)
{ s[i]=n%2;
m=n/2;
n=m;
}
for(j=i;j>=0;j--)
cout<<s[j];
cout<<endl;
}
void octal(int n)
{
int i=0,j,m,s[N];
cout<<"该十进制正整数转化为八进制为:";
for(i=0;n>0;i++)
{ s[i]=n%8;
m=n/8;
n=m;
}
for(j=i;j>=0;j--)
cout<<s[j];
cout<<endl;
}
void main()
{
int n;
cout<<"Please input a positive integer :";
cin>>n;
binary(n);
octal(n);
}