/* Lab : Lab6 Day : Tuesday [ 09 Sept 08 ] Problem Number: 01 Problem Title : Computing x^y without any multiplication Theory : The problem follows incremental method for writing code for power function Stages of programming are as follows 1. Write a method "Add" to find sum of two number 2. Use above function to write a method "Multiply" that calculates multiplication of two mumbers. Solution Strategy : to find a X b, add a to zero b number of times. 3. Use above finction "Multiply" to write a method "Power" that finds x^y. Solution Strategy : to find a ^ b, multiply a to one b number of times. */ class sol_lab6_prob01{ //method "Add" to find sum of two number public static int Add(int a, int b) { return a + b ; } //method "Multiply" that calculates multiplication of two mumbers public static int Multiply(int a, int b) { int i; int mulResult; mulResult = 0; for( i = 1 ; i <= b ; i = i + 1 ) { mulResult = Add( mulResult, a ) ; } return mulResult ; } //method "Power" that finds x^y. public static int Power(int a, int b) { int i; int powResult; powResult = 1; for( i = 1 ; i <= b ; i = i + 1 ) { powResult = Multiply( powResult, a ) ; } return powResult ; } public static void main(String args[]) { int x; int y; x = 10; // Assign any test value here to x y = 5; // Assign any test value here to y System.out.println("\n " + x + "^" + y + " :" + Power(x,y)); } }