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

各路高人,帮帮忙,就快考试了。怎么会是RUNTIME ERROR 呢?

Posted by tigerqian at 2005-01-07 17:21:51 on Problem 1218
#include <stdio.h>

#include <malloc.h>

void main(){
	int i,j,n,sum=0,m,l,*p;
	scanf("%d\n",&l);
	for(m=0;m<l;m++){sum=0;
	scanf("%d",&n);
	p=(int*)malloc(n*sizeof(int));if(!p) free(p);
	for(j=1;j<=n;j++) p[j]=1;
	for(j=2;j<=n;j++){
		for(i=j;i<=n;i++){
			if(i%j==0) p[i]=p[i]*(-1);
		else p[i]=p[i]*1;
		}
	}
	for(j=1;j<=n;j++){
		if(p[j]==1) sum++;}
	printf("%d\n",sum);
	}
}












	

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