Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的错误在哪

Posted by wybkl88 at 2004-09-29 22:52:26 on Problem 1862
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator