csu 1049 第一次串讲——输入输出练习题

C++好处理一些,C语言使用 log10(double x) 计算 x 整数部分的位数(结果要 +1):

 1 # include <stdio.h>
2 # include <math.h>
3
4 int main()
5 {
6 int n, j, tmp;
7 double x, tot;
8
9 freopen("in.txt", "r", stdin);
10 freopen("out.txt", "w", stdout);
11
12 while (~scanf("%d%d", &n, &j))
13 {
14 tot = 0;
15 while (n--)
16 {
17 scanf("%lf~", &x);
18 tot += x;
19 }
20 j -= (int)((log10(tot)) + 5);
21 while(j-- > 0) putchar(' ');
22 printf("%.3lf\n", tot);
23 }
24
25 return 0;
26 }

posted on 2012-03-13 11:48  getgoing  阅读(242)  评论(0编辑  收藏  举报

导航