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;}
BOM (Bill of Materials)是我们常说的物料清单。BOM是制造业管理的重点之一,用于记载产品组成所需要的全部物料(Items)。物料需求的计算是从最终产品开始,层层往下推算出部件,组件,零件和原材料的需求量。这…