Page 290 - CA_Blue( J )_Class9
P. 290

You will get the following output:
                         Fibonacci Series upto 10th term :
                         0, 1, 1, 2, 3, 5, 8, 13, 21, 34

                                                         VARIABLE DESCRIPTION
                             NAME              DATATYPE                           DESCRIPTION
                        a                int                    First Number
                        b                int                    Second Number
                        c                int                    Third Number
                        i                int                    Loop Variable
                        n                int                    No. of Terms

                                  Programs based on printing simple series, summation of simple series.
                   Program 13
                                  S  =  -1 + 2 - 3 + 4 - 5 + 6 - 7 + 8 - 9 + ……………… + Nth
                     1     import java.util.*;                                       //importing “util”package

                     2     class sumseries                                           //class name
                     3     {
                     4         public static void main()

                     5         {
                     6             Scanner sc = new Scanner(System.in);

                     7             int n,i,sum=0;                                    // Declaration of Variable
                     8             System.out.print("Enter nth term : ");

                     9             n=sc.nextInt();
                   10              for(i=1;i<=n;i++)                                 //Loop

                   11              {
                   12                  if(i%2==0)                                    //checking of even or odd

                   13                      sum = sum + i;                            //calculation of sum
                   14                  else

                   15                      sum = sum - i;
                   16              }

                   17              System.out.println("Sum of series : "+sum); //Displaying of sum
                   18          }

                   19      }
                  You will get the following output:
                         Enter nth term : 9
                         Sum of series : -5









                   288    Touchpad Computer Applications-IX
   285   286   287   288   289   290   291   292   293   294   295