程序代码:
#include <stdio.h> void foo( unsigned m, unsigned n ) { printf( "%u", m/n ); m %= n; if( m != 0 ) { putchar( '.' ); unsigned mark[100] = { 0 }; for( unsigned i=1; m!=0; ++i ) { if( mark[m] != 0 ) { printf( "\nfrom %u to %u", mark[m], i-1 ); break; } else { mark[m] = i; putchar( '0' + m*10/n ); m = m*10%n; } } } putchar( '\n' ); return; } int main( void ) { foo( 100, 2 ); foo( 100, 3 ); foo( 136, 90 ); foo( 77, 78 ); }