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