| ||||||||||
| 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>
#define MAXN 100
int Num[MAXN];
int fabnaci(int n)
{
int a=0;int b=1;int i=2;int c;
if(n==0)
return 0;
if(n==1)
return 1;
while(i<=n)
{
c=(a+b)%10000;
a=b;
b=c;
i++;
}
return c;
}
int main()
{
int j=0,counter=0;
do
{
scanf("%d",&Num[j]);
if(Num[j]!=-1)
{
j++;
counter++;
}
else
break;
}while(1);
j=0;
while(j<counter)
printf("%d\n",fabnaci(Num[j++]));
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator