解题思路:
此代码在水仙花数问题1里面有描述,具体过程就不解释了;
注意事项:
参考代码:
思路1:
#include <stdio.h> #include <math.h> void panduan( int N ); int main() { for ( int i = 100; i <= 999; i++ ) { panduan( i ); } return(0); } void panduan( int N ) { int sum = 0, N1 = N; while ( N != 0 ) { sum = sum + pow( (N % 10), 3 ); N /= 10; } if ( sum == N1 ) printf( "%d\n", sum ); return; }
思路2:(c++)
#include<iostream> using namespace std; int main() { cout<<153<<endl; cout<<370<<endl; cout<<371<<endl; cout<<407<<endl; return 0; }
0.0分
0 人评分