C语言求水仙花数
别的不说了,上码程序代码:
#include <stdio.h> #include <stdlib.h> int main() { int x; int start = 1; int end = 1; int count; printf( "输入位数:" ); scanf( "%d", &x ); for( count = 1; count < x; count++ ) { start *= 10; } for( count = 1; count <= x; count++ ) { end *= 10; } for( ; start < end; start++ ) { int t = start; int sum = 0; int digit; do{ digit = t % 10; t /= 10; int p = digit; int j = 0; while( j < x - 1 ) { p *= digit; j++; } sum += p; }while( t > 0 ); if( sum == start) { printf(">%d\n", start); } } system ( "pause" ); return 0; }
小白入门使用,大佬轻喷!