循环结构特别注意 对某些元素重新赋值
找不出错误!!!
# include<stdio.h>
int main()
{
int N,i,t,j;double a[1000]={0},b[1000]={0},r,x;
scanf("%d",&N);
for(i=0;i<N;i++) ///对数组赋值
{
scanf("%lf",&r);
a[i]=1.33*3.14*r*r*r;
b[i]=1.33*3.14*r*r*r;
}
for(j=0;j<N-1;j++) ////对数组a【】排序 从大到小
{
for(i=0;i<N-1-j;i++)
{
if(a[i]<a[i+1])
{
t=a[i];a[i]=a[i+1];a[i+1]=t;
}
}
}
for(i=0;i<N;i++) //a【】中是排序后数据 b【】中对应的是输入时的数据 也就是说j+1就是输入的顺序
{
for(j=0;j<N;j++)
{
x=a[i]-b[j]; //判断 两者是否相等
if(fabs(x)<1e-6)
{t=j+1; //相等 输出顺序
printf("%.2lf %d
",a[i],t);
x=2.0;
break;
}
}
}
return 0;
}