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

Re:我的程序为什么总是runtime error,在vc上运行没错啊?

Posted by hanj04 at 2005-01-06 19:31:58 on Problem 1011
In Reply To:我的程序为什么总是runtime error,在vc上运行没错啊? Posted by:90401461 at 2004-12-22 21:35:00
> 我的程序为什么总是runtime error,在vc上运行没错啊?
> 请各位强人指点迷津,多谢多谢。
> 程序如下:
> #include <stdio.h>
> #include <malloc.h>
> void main(){
> 	int n,i,j,max;
> 	int *length;
> 	scanf("%d",&n);
> 	length=(int*)malloc(n*sizeof(int));
> 	if(!length)return;
>     while(n!=0){
> 		for(i=0;i<n;i++)scanf("%d",&length[i]);
> 		max=length[0];
> 		for(i=1;i<n;i++){
> 			if(length[i]>max)max=length[i];
> 		}
> 		int sum=0;
> 		for(i=0;i<n;i++)sum+=length[i];
> 		for(j=n;j>=1;j--){
> 			if(sum%j==0&&sum/j>=max){
> 				printf("%d\n",sum/j);
> 				break;
> 			}
> 		}
> 		scanf("%d",&n);
> 	}
> 	free(length);
> }

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