- #import <Foundation/Foundation.h>
- bool func(int n)
- {
- int sum = n;
- int tmp;
- while(n != 0)
- {
- tmp = n%10;
- sum -= tmp*tmp*tmp;
- n /= 10;
- }
- if(sum == 0)
- {
- return true;
- }
- return false;
- }
- int main(int argc, const char * argv[])
- {
- int i = 0;
- for(i = 0 ; i <= 1000 ; i++)
- {
- if(func(i))
- {
- NSLog(@"%d是水仙花数" , i);
- }
- else
- {
- //NSLog(@"%d不是水仙花数" , i);
- }
- }
-
- return 0;
- }
复制代码 |