Posts

Showing posts from June, 2023

Design And Analysis Of Algorithm

Image
  Implement following algorithm in iterative and recursive manner:  A. GCD algorithm  B. Factorial algorithm  C. Fibonacci algorithm Factorial Algorithm import java.util.Scanner; public class Factorial {     public static void main ( String [] args ) {         int choice ;     Scanner scanner = new Scanner ( System . in );         do {         System . out . print ( "Enter a number: " );         int number = scanner . nextInt ();         System . out . println ( "Select an approach:" );         System . out . println ( "1. Iterative" );         System . out . println ( "2. Recursive" );     System . out . println ( "3.Stop the Program" );         System . out . print ( "Enter your choice: " );          choice = scanner . nextInt ();         long startTime = System . nanoTime (); // Start execution time         long result ;         switch (choice) {             case 1 :                 result = factorialItera