2012年12月11日
摘要: 题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数 本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。2.程序源代码: 1 #include<stdio.h> 2 int main() 3 { int i,j,k,n; 4 printf("water flower number is:\n"); 5 for(n=100;n<1000;n++) 6 { i=n/100; /*分解出百位*/ 7 k=n/1 阅读全文
posted @ 2012-12-11 17:28 猿人谷 阅读(324) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>int main(){ int n,k,p; printf("输入阶乘的基数n:\n"); scanf("%d",&n); p=1; k=1; while(k<=n) { p=p*k; k++; } printf("%d的阶乘为%d\n",n,p); return 0;} 阅读全文
posted @ 2012-12-11 17:14 猿人谷 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 int main() 3 { int i,j; 4 for(i=1;i<=9;i++) 5 { 6 for(j=1;j<=i;j++) 7 printf("%d*%d=%-4d",j,i,i*j); 8 printf("\n"); 9 }10 return 0;11 } 阅读全文
posted @ 2012-12-11 17:04 猿人谷 阅读(326) 评论(0) 推荐(0) 编辑
摘要: 题目:打印楼梯,同时在楼梯上方打印两个笑脸。 1.程序分析:用i控制行,j来控制列,j根据i的变化来控制输出黑方格的个数。2.程序源代码: 1 #include<stdio.h> 2 int main() 3 { int i,j; 4 printf("\1\1\n"); //打印两个笑脸 5 for(i=1;i<11;i++) 6 { for(j=1;j<i;j++) 7 printf("%c%c",23,23); //23这个数字可以是任意数,代表该数所对应的符号 8 printf("\n"); 9 }10 阅读全文
posted @ 2012-12-11 16:53 猿人谷 阅读(1203) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1049 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n,u,d,s,t; 6 while (cin >> n >> u >> d) 7 { 8 if (n==0) 9 return 0;10 else11 {12 s=0;13 t=0;14 while ... 阅读全文
posted @ 2012-12-11 16:36 猿人谷 阅读(222) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2393 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n,a,b,c; 6 cin >> n; 7 for (int i=1;i<=n;i++) 8 { 9 cin >> a >> b >> c;10 if (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)11 {12 cou... 阅读全文
posted @ 2012-12-11 16:35 猿人谷 阅读(393) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2560Problem DescriptionWe divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N*M gr 阅读全文
posted @ 2012-12-11 16:33 猿人谷 阅读(256) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1096Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of inpu 阅读全文
posted @ 2012-12-11 16:31 猿人谷 阅读(331) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1095Problem DescriptionYour task is to Calculate a + b.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers a and b you should output the sum of a and 阅读全文
posted @ 2012-12-11 16:29 猿人谷 阅读(586) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1094Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.OutputFor each test case you should outp 阅读全文
posted @ 2012-12-11 16:28 猿人谷 阅读(456) 评论(0) 推荐(0) 编辑