Page 448 - computer science (868) class 11
P. 448

5
              6
              ENTER THE NUMBER TO BE SEARCHED
              5
              YES. THE POSITION IS 4
                                                         Variable Description
                 NAME         TYPE                                       DESCRIPTION
               n           int          Size of the Array
               sno         int          Number to be searched
               i           int          Loop Variable

               j           int          Loop Variable
               max         int          Maximum index
               min         int          Minimum index
               mid         int          Middle index

               p           int          Position where number is found
               t           int          Temporary variable
               ar[]        int[]        Array[]




                Program 4      Define a class Smith to check whether a number is a Smith number or not.
                               Eg: A smith number is a composite number, the sum of whose digits is the sum of the digits of
                               its prime factors obtained as a result of prime factorisation (excluding 1). The first few such
                               numbers are 4, 22, 27, 58, 85, 94, 121, …
                               Example:
                               N = 666
                               Prime factors are 2, 3, 3, 37
                               Sum of the digits = 6 + 6 + 6 = 18
                               Sum of the digits of the factors 2 + 3 + 3 + 3 + 7 = 18
                               Hence, 666 is a Smith Number.
                               The data members and the member methods are defined as follows:
                               int n                           :   To store the number
                               Member Methods
                               boolean composite(int x)        :  To check whether a number is composite or not

                               int sum_of_digits(int x)        :  To find the sum of the digits of a number
                               int sum_prime(int x)            :  To find the sum of the prime factors of the number
                               Also, write the main method to call the function.

                 1       import java.util.*;

                 2       class Smith
                 3       {

                 4           int n;




                446446  Touchpad Computer Science-XI
   443   444   445   446   447   448   449   450   451   452   453