{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c12_ps05_sol - C12 1 Algorithm a Get the number from the...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
C12 1. Algorithm a. Get the number from the user b. If the number is >= 1 then i. For I in 1 .. number loop ° Factorial := Factorial * I; c. Else i. Display Cannot Compute Factorial d. Display Computed Factorial to the User Code Listing GNAT 3.13 p ( 20000509 ) Copyright 1992 - 2000 Free Software Foundation, Inc. Compiling: c:/docume~ 2 / joeb /desktop/ 16070 /codeso~ 1 /factorial_with_iteration.adb (source file time stamp: 2003 - 10 - 02 03 : 57 : 26 ) 1 . ------------------------------------------------------ 2 . -- Program to find the factorial of a number using 3 . -- iteration. 4 . -- Programmer : Joe B 5 . -- Date Last Modified : October 01, 2003 6 . ------------------------------------------------------ 7 . 8 . 9 . with Ada.Text_Io; 10 . with Ada.Integer_Text_Io; 11 . 12 . procedure Factorial_With_Iteration is 13 . Factorial : Integer := 1 ; -- initializise factorial to 1 14 . Num : Integer; -- variable used to get input from the user 15 . begin 16 . -- get the number from the user 17 . Ada.Text_Io.Put( "Please Enter A Number : " ); 18 . Ada.Integer_Text_Io.Get(Num); 19 . Ada.Text_Io.Skip_Line; 20 . 21 . if Num >= 1 then 22 . 23 . -- compute factorial 24 . for I in 1 .. Num loop 25 . Factorial:= Factorial * I; 26 . end loop ; 27 .
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern