【求助】求旁观者帮忙找出导致附件中错误的原因,谢谢!
程序代码:
//编写函数,把任意十进制正整数转换成二进制。 //要求:不得按逆序输出,在主函数中输出; # include <stdio.h> int hexcon ( int * );//进制转换 int main (void) { int num[ ] = { 0 }; int flag = 0;//记录数组元素个数; int i = 0; flag = hexcon ( num ); printf ("输出二进制数:\n"); for ( i = flag-1; i >= 0; i-- ) { printf ("%d ", num[i] ); } printf ("\n"); return 0; } //进制转换 int hexcon ( int * num ) { int i = 0; int intger = 0;//正整数,商; int rem = 0;//余数; printf ("请输入任意十进制正整数:\n "); scanf ("%d", &intger ); while ( intger!=0 ) { rem = intger%2;//余数; intger = intger/2;//商数; num[i] = rem;//存储; i++; } return i; }