Inbound 3600796691372883674
Inbound 3600796691372883674
Inbound 3600796691372883674
Before coding a program, we must have first an idea how to solve it. Such that,
we have to prepare first a step by step solution also known as ALGORITHM.
5. Traverse using a while loop. The loop will continue to execute every time the value
of (i<=num) is TRUE.
a. Update the factorial in each iteration of the number.
Fact = Fact * i
b. Increment the loop variable.
Consider typing the sample source code below. Replace the Name, Date and Block. The
code was based from the Algorithm stated above:
import java.util.*;
Sample Output
Enter an Integer value [1..10]: 5
The Factorial of 5 is: 120
UNIVERSIDAD DE DAGUPAN
SCHOOL OF INFORMATION TECHNOLOGY EDUCATION
ITC04 | DATA STRUCTURES & ALGORITHMS
Semester: 1st Semester | Academic Year: 2024-2025 2
Laboratory Exercise #1 Q&A
Name: Jofrey M. Acosta ______________________________________________
Block 3____
Date Submitted: September 5____, 2024
Run and test the program for values 13, 14 and 15, respectively.
UNIVERSIDAD DE DAGUPAN
SCHOOL OF INFORMATION TECHNOLOGY EDUCATION
ITC04 | DATA STRUCTURES & ALGORITHMS
Laboratory Exercise #1 The Updated Source Code
After performing Question #4. Copy & Paste all the New Java Code below...
Question 1: What have you observed about the result of Factorial for 13, 14
and 15 respectively? (Paste screenshot and resize it below. Choose one result
only between 13! Or 14! Or 15!)
ANS;
- 13 = 6,227,020,800
- 14 = 87,178,291,200
- 15 = 1,307,674,368,000
Question 2: What do you think might be the effect of not knowing the
maximum value for an integer data type?
ANS;
- Not knowing the maximum value of an integer data type can lead to
issues such as overflow errors, performance inefficiencies, program
ANS;
- To handle larger factorials like \(13!\) and beyond, use big integer data
types, factorial libraries, or approximation methods like Stirling’s
approximation. These approaches ensure correct calculations without
overflow issues.
Question 4: What will be appropriate solution that will allow the program to
accept only integer numbers from 1 up to 10?
ANS;
Input Validation: Check if the input is an integer and falls within the range of 1
to 10. If it doesn’t, reject the input and prompt the user again.
Phyton example;
While True:
Try:
Break
Else:
Except ValueError:
Kindly indicate your Block in the Subject portion of your e-mail composition.