Page 224 - CA_Blue( J )_Class9
P. 224

Write a program to find and display the sum of the following series:
                   Program 13
                                  s = 1+4+9+16….nth term

                     1     import java.util.*;
                     2     class prog_loop5

                     3     {
                     4         public static void main()

                     5         {
                     6             Scanner sc = new Scanner (System.in);
                     7             int n,i;

                     8             double sum=0.0;

                     9             System.out.println("Enter n terms: ");
                    10             n=sc.nextInt();
                    11             for (i=1; i<=n; i++)

                    12                 sum=sum + (i*i);
                    13             System.out.println("Sum of the Series :"+sum);

                    14         }
                    15     }

                  You will get the following output:
























                                  Write a program to find and display the sum of the following series:
                   Program 14
                                            3
                                  s = a +a +a +a +a …. n  terms
                                               4
                                      1
                                         2
                                                  5
                                                      th
                     1     import java.util.*;
                     2     class prog_loop6
                     3     {
                     4         public static void main()

                     5         {



                   222    Touchpad Computer Applications-IX
   219   220   221   222   223   224   225   226   227   228   229