It is easy to code since each method will be a small

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: oblem. • It is easy to code since each method will be a small piece of code. • The program becomes more manageable. • It reduces the chances of logical errors. 4 Two Examples of Structured Programming • Printing a Diamond with a given half-width • Computing the Maximum value permutation for an integer 5 P : Computing Max Perm for an integer P : MaxPerm(n) 6 P : Computing Max Perm for an integer P : MaxPerm(n) Q: Perm_with_Largest_Digit_at_MSI(n) 7 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) 8 Value_of_Digit_at_Index(n,index) 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) 9 Value_of_Digit_at_Index(n,index) The method Num of digits(int n) // function for computing number of digits in n public static int Num_of_Digits(int n) { int digits = 0; while(n>0) { digits = digits + 1; n = n/10; } return digits; } 10 The method Power of Ten(int i) // function for computing 10ˆi. pu...
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