/* Lab : Lab5 Day : Tuesday [ 02 Sept 08 ] Problem Number: 02 Problem Title : Depth of Number function Theory : the program requires to find the sum of squires of all degits of a number and this new sum becoms */ class sol_lab5_prob02{ public static void main(String args[]) { int i; // Counter variable to generate all numbers from 2 to 99 int num; // current nuber whose depth is to be found int digitAtUnitPlace; // digit at unit place od number num; for ex. if num = 21, digitAtUnitPlace = 1 int sumOfSquireOfDigits; // sum of squire of digits of number num; For ex. if num = 21, sumOfSquireOfDigits = 2^2 + 1^2 = 5 int depth_f; // depth of number num int maxDepth = 1; // variable to track maximum depth so far int maxDepthNum = 1 ; // variable to track number whose depth is maxDepth for( i = 2 ; i < 100 ; i++ ) // generate number from 2 to 99 { num = i; depth_f = 0; while( num != 1 && num != 89 ) { depth_f = depth_f + 1; // Findind sum of squire of digits of num sumOfSquireOfDigits = 0; while( num > 0 ) { digitAtUnitPlace = num % 10 ; sumOfSquireOfDigits += ( digitAtUnitPlace * digitAtUnitPlace ) ; num = num / 10 ; } num = sumOfSquireOfDigits; } if(depth_f >= maxDepth ) { maxDepth = depth_f; maxDepthNum = i; } } System.out.println("\nNumber <" + maxDepthNum + "> has maximim depth_f value <"+maxDepth+"> among [2..99] :"); } }