Segmentation fault:段错误,检查是否有数组越界,指针异常,访问到不应该访问的内存 10
运行会放出上面的提示#include<stdio.h>main(){intn,i,t,j=1;doubleavg1,avg2,a[100],s=0,v=0;while(s...
运行会放出上面的提示
#include<stdio.h>
main()
{
int n,i,t,j=1;
double avg1,avg2,a[100],s=0,v=0;
while(scanf("%d",&n) !=EOF)
{ s=0;
j=1;
t=n;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
s=s+a[i];
}
avg1=s*1.0/n;
while(j!=n){
for(i=j;i<n;i++){
v=v+a[i];
}
题目下面
题目描述
Given N numbers in a line, we can determine a continuous subsequence by giving its start position and its length.
PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.
You are to calculate the best result Roy can get, assuming PMH is very clever.
输入
There are multiple testcases.
Each testcase begins with a line containing N only.
The following line contains N numbers, separated by spaces.
输出
For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.
样例输入
10
2 10 4 6 5 10 10 2 3 2
样例输出
5.777778
avg2=v*1.0/(n-j);
if(avg2>avg1){
avg1=avg2;
}
v=0;
j++;
}
printf("%.6lf\n",avg1);
}
}
#include<stdio.h>
main()
{
int n,i,t,j=1;
double avg1,avg2,a[100],s=0,v=0;
while(scanf("%d",&n) !=EOF)
{ s=0;
j=1;
t=n;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
s=s+a[i];
}
avg1=s*1.0/n;
while(j!=n){
for(i=j;i<n;i++){
v=v+a[i];
}
avg2=v*1.0/(n-j);
if(avg2>avg1){
avg1=avg2;
}
v=0;
j++;
}
printf("%.6lf\n",avg1);
}
}
这是我的程序 上面有点不全 展开
#include<stdio.h>
main()
{
int n,i,t,j=1;
double avg1,avg2,a[100],s=0,v=0;
while(scanf("%d",&n) !=EOF)
{ s=0;
j=1;
t=n;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
s=s+a[i];
}
avg1=s*1.0/n;
while(j!=n){
for(i=j;i<n;i++){
v=v+a[i];
}
题目下面
题目描述
Given N numbers in a line, we can determine a continuous subsequence by giving its start position and its length.
PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.
You are to calculate the best result Roy can get, assuming PMH is very clever.
输入
There are multiple testcases.
Each testcase begins with a line containing N only.
The following line contains N numbers, separated by spaces.
输出
For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.
样例输入
10
2 10 4 6 5 10 10 2 3 2
样例输出
5.777778
avg2=v*1.0/(n-j);
if(avg2>avg1){
avg1=avg2;
}
v=0;
j++;
}
printf("%.6lf\n",avg1);
}
}
#include<stdio.h>
main()
{
int n,i,t,j=1;
double avg1,avg2,a[100],s=0,v=0;
while(scanf("%d",&n) !=EOF)
{ s=0;
j=1;
t=n;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
s=s+a[i];
}
avg1=s*1.0/n;
while(j!=n){
for(i=j;i<n;i++){
v=v+a[i];
}
avg2=v*1.0/(n-j);
if(avg2>avg1){
avg1=avg2;
}
v=0;
j++;
}
printf("%.6lf\n",avg1);
}
}
这是我的程序 上面有点不全 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询