c程序acm编程

来源:百度知道 编辑:UC知道 时间:2024/06/13 21:21:24
帮忙用C语言求解一道很简单的ACM题
问题:In this problem, you are to write a program to calculate the sum of inputs. The input file consists exactly one case and you should print your result on a single line.

Input Specification
The input consists of N lines, each of which contains one number.

Output Speciication
For the numbers your program reads, your program should print the sum of them to the stdout on a single line. You should pay more attention to the output precision.

Hint
In C++ language, cout.precision is used to set the effective numbers of output.
You may use it in the program. E.g. cout.precision(15).

In C language, format "%.2lf" may be used.
我提交了一下网友回复我的两个程序,但是都是运行不出来,第一个是compilation error并给出如下英文
/tmp/jtest/89/434610.cpp:2: error: stray `163` in program
/tmp/jtest/89/434610.cpp:2: error: stray `168` in program
/tmp/jtest/89/434610.cpp:2: error:

#include <stdio.h>
int main()
{
int n,i;
double sum=0,a;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%lf",&a);
sum+=a;
}
printf("%.2lf\n",sum);
return 0;
}

#include <stdio.h>
int n,i;
double sum,cur;
scanf("%d",&n);
sum=0;
for(i=0;i<n;i++)
{
scanf("%lf",&cur);
sum+=cur;
}
printf("%.2lf",sum);//精度自己设置
return 0;
}

In C++ language

不是要求用c++吗?干吗还用c呢?应该是你选择语言的时候出问题了吧?