| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我的错误在哪#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void BubbleSort(int a[],int n)
{
int i,j,flag=1;
int temp;
for(i=1;i<n && flag==1 ;i++)
{
flag =0;
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
flag = 1;
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
void main()
{
int i,n;
int *a,j;
float k;
scanf("%d",&n);
if((a=(int *)malloc(n * sizeof(int)))== NULL)
{
printf("The memory space is not enough!\n");
exit(0);
}
for(i=0;i<n;i++)
{
scanf("%d",&j);
a[i] = j;
}
BubbleSort(a,n);
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(j=1;j<n;j++)
{
a[n-j-1] = 2 * sqrt(a[n-j-1] * a[n-j]);
BubbleSort(a,n-j);
}
printf("%.3f\n",(float)a[0]);
printf("\n");
free(a);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator