10205101503 edited 3 年,9 月前

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int fib2(int n){
    int first=-1,second=1,sum;
    for(int i=0;i<=n;i++){
        sum=first+second;
        first=second;
        second=sum;
    }
    return sum;
}

int main()
{
int T;
scanf("%d",&T);
int k=0;
for(int i=0;i<T;i++){
int n;
scanf("%d",&n);
printf("case #%d:\n",k);
k++;
printf("%d\n",fib2(n));
}
}

Comments