intprime(int p){int count =0;if(p==1)return0;for(int i =2; i <= p; i++){if(p % i ==0)
count++;}if(count ==1)return1;elsereturn0;}intPrimeSum(int m,int n){int sum =0;for(int i =(m<=n?m:n); i <=(n>=m?n:m); i++){if(prime(i)==1)
sum += i;}return sum;}
6-7 使用函数输出水仙花数
#include<math.h>intnarcissistic(int number){int count =0;int sum1 =0;int num = number;while(number){
number /=10;
count++;}int sum =0;
number = num;while(number){
sum1 = number %10;
sum +=(int)(pow(sum1, count));
number /=10;
sum1 =0;}if(num == sum)return1;elsereturn0;}voidPrintN(int m,int n){for(int i =(m <= n ? m : n)+1; i <(n >= m ? n : m); i++){if(narcissistic(i)==1){printf("%d\n", i);}}}
二.编程题
7-1 寻找自守数
#include<stdio.h>intZISHOUnum(int p){int num =0, count =0;
num = p * p;while(p !=0){if(p %10!= num %10)return0;
p /=10;
num /=10;}return1;}intmain(){int n =0, m =0;int count =0;scanf("%d %d",&n,&m);for(int i = n; i <= m; i++){if(ZISHOUnum(i)){
count++;printf("%d\n", i);}}if(count ==0){printf("None\n");}return0;}