Page 199 - Computer science 868 Class 12
P. 199

10                  return n;
                  11              }

                  12              if(n==1)
                  13                  return 0;
                  14              else

                  15              if(n==2)

                  16                  return 1;
                  17              else
                  18                  sum=a+b;

                  19              for(int i=3; i<=n; i++)
                  20              {

                  21                  curfibo = a+b;
                  22                  sum = sum+curfibo;

                  23                  a = b;
                  24                  b = curfibo;

                  25              }
                  26              return sum;

                  27          }
                  28          void main()

                  29          {
                  30              int n, s;

                  31              Scanner sc=new Scanner(System.in);
                  32              System.out.println("Enter the nth term ");

                  33              n=sc.nextInt();
                  34              s=fib(n);

                  35              System.out.println("Sum is " + s);
                  36          }

                  37      }
                 The output of the preceding program is as follows:
                 Enter the nth term

                 9

                 Sum is 54









                                                                                                                       197
                                                                                                 Statements and Scope  197
   194   195   196   197   198   199   200   201   202   203   204