| ||||||||||
| 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 <stdio.h>
#include <math.h>
int f(int k)
{
int i,a[1000];
if(k==0) a[k]=0;
else
for(i=1;i<=k;i++)
{ if(a[i-1]>=i) a[i]=a[i-1]-i;
else a[i]=a[i-1]+i;
}
return a[k];
}
void main ()
{
int a;
for(;;)
{
scanf("%d",&a);
if(a==-1) break;
printf("%d\n",f(a));
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator