Page 216 - Computer science 868 Class 12
P. 216

}
                    while(i>=1);
                Ans.  int i=20;
                    while(i>=1)
                    {
                    System.out.println(i*2);
                    i=i-2;
                    }
                  7.  The following is a public member function that finds whether an integer in the parameter is a perfect number or not. There are
                    five places in the code marked as ?1?,?2?,?3?,?4? and ?5? which must be replaced by expressions or statements so that the
                    program works correctly. Answer the questions given after the function.
                      int function(int n)
                    {
                     int ?1?;
                     for(int j=1;?2?;j++)
                     {
                     if(?3?)
                     sum ?4?;
                     }
                     if(?5?)
                     return 1;
                     else
                     return 0;
                    }
                     (i)   What is the expression at ?1?
                    (ii)   What is the expression at ?2?
                    (iii)  What is the expression at ?3?
                    (iv)  What is the expression at ?4?
                    (v)   What is the expression at ?5?
                Ans.  ?1? sum=0
                     ?2? j<n
                     ?3? n%j==0
                     ?4? =sum+j
                     ?5? n==sum
                  8.  State the final value of q at the end of the following program segment.
                    int m, n, p=0, q=0;
                        for(m=2; m<=3; ++m)
                        {
                            for(n=1; n<=m; ++n)
                          {
                                p=m+n-1;
                              if(p%3==0)
                                q+=p;
                           else
                                q+=p+4;
                          }
                        }
                        System.out.println(p+" : "+q);
                Ans.  5 : 29


                214214  Touchpad Computer Science-XII
   211   212   213   214   215   216   217   218   219   220   221