Repository navigation
Expand file tree
/
Copy pathtask3.sh
More file actions
59 lines (49 loc) · 1.4 KB
/
Copy pathtask3.sh
File metadata and controls
59 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
echo "Enter a:"
read a
echo "Enter b:"
read b
echo "Enter c:"
read c
# Ask the user which option they want
echo "Which option do you want?"
echo "1) Find a limited number of terms of the sequence and print them in order."
echo "2) Find a term in a position chosen by the user and determine whether this term is a factor of a number chosen also by the user."
read option
# Option 1
if [ $option -eq 1 ]
then
# Ask the user how many terms they want
echo "How many terms do you want?"
read num_terms
# Calculate and print the terms
product=1
for (( n=1; n<=$num_terms; n++ ))
do
term=$((a*n*n + b*n + c))
echo "$term"
product=$((product * term))
done
# Print the product of the terms
echo "The product of the terms is $product"
# Option 2
elif [ $option -eq 2 ]
then
# Ask the user which term they want
echo "Which term do you want?"
read term_num
# Calculate the term and print it
term=$((a*term_num*term_num + b*term_num + c))
echo "The $term_num term is $term"
# Ask the user for a number to check
echo "Enter a number to check if the term is a factor:"
read check_num
# Check if the term is a factor of the number
if [ $((check_num % term)) -eq 0 ]
then
echo "This term is a factor of $check_num."
else
echo "This term is not a factor of $check_num."
fi
else
echo "Invalid option."
fi