Podcast
Questions and Answers
What does the function palindrome
primarily check for?
What does the function palindrome
primarily check for?
- If a number is an Armstrong number
- If a number is even
- If a number is the same when reversed (correct)
- If a number is a prime number
Which of the following statements about the prime
function is true?
Which of the following statements about the prime
function is true?
- It checks if a number is even.
- It compares the number with 1 to check for primality.
- It counts from 2 to the input number to check factors. (correct)
- It has no conditions to validate primality.
What is the output of the palindrome
function if the input is 121?
What is the output of the palindrome
function if the input is 121?
- Error in the function
- It isn't a Palindrome
- It is a Palindrome (correct)
- Output is undefined
In the rev
function, what is the purpose of the loop?
In the rev
function, what is the purpose of the loop?
What condition does the c == n
check in the last function related to the Armstrong number?
What condition does the c == n
check in the last function related to the Armstrong number?
Flashcards are hidden until you start studying
Study Notes
Palindrome Function
- Checks if a number is a palindrome by reversing its digits.
- Initializes
a
to the original number andr
to 0 to hold the reversed number. - Uses a loop to extract each digit: multiplies
r
by 10 to shift digits and adds the last digit ofn
usingn % 10
. - Compares the reversed number
r
with the original numbera
to determine if it is a palindrome. - Outputs "It is a Palindrome" if true, otherwise outputs "It isn't a Palindrome".
Prime Function
- Intended to check if a number is prime starting from
i = 2
. - Uses a
for
loop to iterate from2
ton-1
for divisibility checking. - An individual number is considered prime if it has no divisors other than
1
and itself.
Armstrong Function
- Checks if a number is an Armstrong number (sum of its digits raised to the power of the number of digits equals the number itself).
- Initializes
c
to zero for accumulating the sum of digits raised to the third power. - The loop processes each digit using modulus and division operations to sum them up.
- Compares the calculated sum
c
withn
for validation. - Outputs "Armstrong No." if they are equal, otherwise outputs "Not Armstrong".
Reverse Function
- Intended to print the reverse of a number.
- Uses a loop to extract each digit from the number
n
through division. - Outputs each digit as it is processed, indicating the result as "Reverse: ".
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.