信仰2016

导航

 

2016年5月12日

摘要: 本次编写的程序有,输出100以内的素数,兔子问题,水仙花数,整数分解,和输出100的阶乘, 其中100以内的素数是用了两个for循环 找出100以内每个数有没有可以整除的数。 兔子问题通过设立两个数组,一个存放当月的成熟兔子数目 一个存放新生的兔子数目。 输出100的阶乘使用字符串, 将数字存入字符 阅读全文
posted @ 2016-05-12 13:32 信仰2016 阅读(114) 评论(0) 推荐(0)
 
摘要: //输出100的阶乘 使用字符串存入阶乘的结果 然后每一位一次计算结果。 #include #include using namespace std; int main() { string a = "1"; for (int i = 1; i = 0; k--) { cout << a[k]; } cout << endl; } return 0; } 阅读全文
posted @ 2016-05-12 13:27 信仰2016 阅读(2823) 评论(0) 推荐(0)
 
摘要: //有一对兔子出生后第三个月起每个月都生一对兔子,加入兔子不死问每个月兔子的总数为多少? #include using namespace std; int main() { int sum[20],chusheng[20]; sum[0] = 2; chusheng[0] = 0; for (int i = 0; i < 20; i++) { if (i < 2) { ... 阅读全文
posted @ 2016-05-12 13:25 信仰2016 阅读(184) 评论(0) 推荐(0)
 
摘要: //判断101-200之间有多少个素数并输出所有素数 #include using namespace std; int main() { int k = 0; for (int sqrt = 101; sqrt <= 200; sqrt++) { for (int i = 2; i < sqrt; i++) { if (sqrt%i == 0)//能被整除的都不是素数 ... 阅读全文
posted @ 2016-05-12 13:24 信仰2016 阅读(3693) 评论(2) 推荐(0)
 
摘要: //例 输入8 输出8=2*2*2 #include using namespace std; int main() { int a, k = 1; while (k) { cout > a; int i = 2; cout << a << "="; for (int j = 0; j < 100; j++) { if (a%i == 0) { a ... 阅读全文
posted @ 2016-05-12 13:21 信仰2016 阅读(168) 评论(0) 推荐(0)
 
摘要: //打印出所有的水仙花数例:153=1*1*1+5*5*5+3*3*3 #include using namespace std; int main() { cout << "水仙花数有:"; for (int i = 100; i < 1000; i++) { int a = i % 10; int b = ((i-a)/10)%10; int c = i/ 100; i... 阅读全文
posted @ 2016-05-12 13:20 信仰2016 阅读(143) 评论(0) 推荐(0)