摘要: #include using namespace std;int sumOfEachNum(int);int main(){ int input; cout>input; cout<<"the sum of each number is:"<<sumOfEachNum(input)<<endl; return 0;}int sumOfEachNum(int a){ int sum =0 ; do { sum += a%10; a /= 10; }while(a != 0); return sum;} 阅读全文
posted @ 2013-10-01 00:45 xuefenhu 阅读(780) 评论(0) 推荐(0) 编辑
摘要: 题目:要求输出所有小于等于n的素数(n>=2,且为正整数)要求:1、每行输出10个素数 2、尽可能采用较优算法#include#include#includeusing namespace std;bool Prime(int); //函数声明int main(){ int input; cout=2):"; cin>>input; static int count = 0; //count为累计的每行素数个数 if(input >= 2) { cout2)不可能是素数,所以上述程序中只对奇数进行了素数的判断。 阅读全文
posted @ 2013-10-01 00:11 xuefenhu 阅读(1684) 评论(0) 推荐(0) 编辑