哈哈···弄好了···
好辛苦的说··调试了好久··草稿纸都用了3张了··
但是··LZ··我担心你看不懂···
其实很简单的···
我在继续完善一下····
等下发上来···
好辛苦的说··调试了好久··草稿纸都用了3张了··
但是··LZ··我担心你看不懂···
其实很简单的···
我在继续完善一下····
等下发上来···
程序代码:#include<stdio.h>
#include<stdlib.h>
#define CLSIO { int c; while( (c=getchar())!='\n' && c!=EOF ); }
int dissociaton( long n , int d ) ; // 分解N
int main( void )
{
int iput = 1 ; // 记录输入状况和EOF
while(iput)
{
puts ("输入:一个数 N (0<=N<=1000000000)");
puts ("找到最小的正整数Q,使得Q的各位数的乘积等于N");
puts ("如果不存在Q,输出-1\n");
long num ; // 获取N
int div = 9 ; // N要除以的数
if ( ( iput=scanf("%d" , &num) ) != 1 || iput==EOF || num<0 || num>1000000000 )
exit(EXIT_FAILURE) ;
if ( num < 10 )
printf( "%d\n" , num+10 ) ;
else
dissociaton( num , div ) ;
CLSIO ;
puts ("\n\n---------------华丽的分割线线---------------\n\n");
}
return 0 ;
}
int dissociaton( long n , int d )
{
if ( d<2 ) return 0 ;
if ( n%d ) dissociaton( n , d-1 ) ;
else
{
if ( n == d )
{
putchar( n +'0') ;
return 1 ;
}
else
{
if ( dissociaton( n/d , d ) )
putchar( d + '0' ) ;
}
}
}
程序代码:#include<stdio.h>
#include<stdlib.h>
#define CLSIO { int c; while( (c=getchar())!='\n' && c!=EOF ); }
void dissociaton( long n ) ; // 分解N
int main( void )
{
int iput = 1 ; // 记录输入状况和EOF
while(iput)
{
puts ("输入:一个数 N (0<=N<=1000000000)");
puts ("找到最小的正整数Q,使得Q的各位数的乘积等于N");
puts ("如果不存在Q,输出-1\n");
long num ; // 获取N
int div = 9 ; // N要除以的数
if ( ( iput=scanf("%d" , &num) ) != 1 || iput==EOF || num<0 || num>1000000000 )
exit(EXIT_FAILURE) ;
dissociaton( num ) ;
CLSIO ;
puts ("\n\n---------------华丽的分割线线---------------\n\n");
}
return 0 ;
}
void dissociaton( long n )
{
char out[13] = {'\0'} ;
int idx=11, div = 9 ;
if ( n<10 ) printf( "%d\n" , n+10 ) ;
else
{
while ( n!=1 && div>1 )
{
if ( n%div ) --div;
else
{
out[idx--] = div +'0' ;
n/=div ;
}
}
div<2 ? puts("-1") : puts(out+idx+1) ;
}
}