{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c12_ps05_sol

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

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

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 .

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

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

{[ snackBarMessage ]}

What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern