C Programming Functions Quiz

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

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?

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

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

<p>To print the reverse of the number (A)</p>
Signup and view all the answers

What condition does the c == n check in the last function related to the Armstrong number?

<p>To verify if the total of cubes equals the original number (D)</p>
Signup and view all the answers

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 and r 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 of n using n % 10.
  • Compares the reversed number r with the original number a 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 from 2 to n-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 with n 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.

Quiz Team
Use Quizgecko on...
Browser
Browser