[Login|Register]
New post

Show post

Search forum

Read post
是不是要注意什么输入格式! [ Topic ] 2011-10-30 22:54:31 purplesday
#include <stdio.h>

int fib(int n)
{
    int array[2]={0,1},temp=0,i;

    if (n == 0)
        return 0;
    else if (n == 1)
        return 1;
    else
    {
        for (i=n; i > 2;i--)
        {
            temp=array[0]+array[1];
            array[0]=array[1];
            array[1]=temp;
        }
        return (array[0]+array[1]);
    }
}

int main(void)
{
    int a[40],i=0,j;

    while ( scanf("%d",&a[i]) != EOF)  i++;
    
    j=0;
    while (j < i )
    {
                                printf("The Fibonacci number for %d is %d\n",a[j],fib(a[j]));
        j++;
    }
                return 0;
}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 2.2ms with 2 query(s).