#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int n,i; double sum=2.0; scanf("%d",&n); double a[1000]={1,2}; for(i=1;i<n;i++){ a[i+1]=a[i]+a[i-1]; sum=sum+a[i+1]/a[i]; } printf("%.2lf",sum); } |
Double click to view unformatted code.