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 |
明白了,else if(1<=p<=k-1)~In Reply To:小弟初学C,不知错在哪里~希望名位大哥大姐指教 Posted by:ybsb at 2006-01-22 23:00:09 > #include <stdio.h> > int main() > { > int sum=0, k=2; > int n; > int i; > int p; > scanf("%d",&n); > while(1) > { > for(i=2;i<=k;i++) > sum+=i; > if(sum<=n&&n<sum+k+1) > break; > sum=0; > k++; > } > p=n-sum; > > if(p==0) > for(i=2;i<=k;i++) > printf("%d ", i); > else if(1<=p<=k-1) > { > for(i=2;i<=k-p;i++) > printf("%d ", i); > for(i=k+2-p;i<=k+1;i++) > printf("%d ", i); > } > else > { > for(i=3;i<=k;i++) > printf("%d ", i); > printf("%d ", k+2); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator