digits int differenceofdigits valueofmaxdigit

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: dex != digits) { int difference_of_digits = value_of_max_digit - digit_at_MSI; int lower_power = Power_of_Ten(max_digit_index-1); new_n = n + (power-lower_power)*difference_of_digits; } return new_n; } 14 The method Max Perm(int n) public static int Max_Perm(int n) { int upper_n; int lower_n; int digits = Num_of_Digits(n); int power= Power_of_Ten(digits); for(int i = digits; i>1; i =i-1) { upper_n= n/power; lower_n= n%power; lower_n= Permutation_with_Max_Digit_at_MSI(lower_n,i); n = upper_n*power+ lower_n; power = power/10; } return n; } 15 P : Computing Max Perm for an integer P : MaxPerm(n) Q: Num_of_Digits(m) Power_of_Ten(i) Perm_with_Largest_Digit_at_MSI(n) Max_Digit_Index(n,digits) 16 Value_of_Digit_at_Index(n,index) II : Common Steps in Problem Solving 1. Und...
View Full Document

This note was uploaded on 02/17/2014 for the course CS 101 taught by Professor Smitamazumdar during the Spring '12 term at IIT Kanpur.

Ask a homework question - tutors are online