Unit summary
n % 10gives the last digit of a number andn / 10removes it; repeating these extracts all the digits.- A palindrome number equals its reverse, built with
rev = rev * 10 + digit. - A prime has exactly two divisors; it is enough to test divisors d with d × d ≤ n.
- Prime factors are found by dividing out each divisor completely.
- A perfect number equals the sum of its proper divisors; in an amicable pair each number equals the divisor sum of the other.
- An Armstrong number equals the sum of its digits, each raised to the number of digits.
- n! is the product of the integers from 1 to n, with 0! = 1; factorials overflow an
intbeyond 12!. - Base conversion validates the digits, accumulates the value to decimal, and uses repeated division to reach the target base.
- Maximum, minimum, sum and average of a sentinel-terminated sequence are computed in one pass with a few variables.
- The else-if ladder selects among ranges; the switch statement selects among constant values.
- Prefix
++and--change the variable before its value is used; postfix forms change it afterwards. breakleaves a loop or switch;continueskips to the next pass of a loop.
Glossary
| Term | Meaning |
|---|---|
| Amicable numbers | Two different positive integers whose proper-divisor sums equal each other. |
| Armstrong number | A number equal to the sum of its digits, each raised to the number of digits. |
| Base | The number of distinct digit symbols used in a positional number system. |
| break | A C statement that exits the nearest loop or switch. |
| Composite number | An integer greater than 1 that is not prime. |
| continue | A C statement that skips to the next loop iteration. |
| Decrement operator | An operator that decreases a variable by one. |
| Digit extraction | Separating the digits of a number using division and remainder. |
| else-if ladder | A chain of conditions tested in order, of which only the first true one is acted upon. |
| Factorial | The product of the integers from 1 to n, with 0! equal to 1. |
| Fall-through | Continuing into the next case of a switch because break was omitted. |
| Increment operator | An operator that increases a variable by one. |
| Maximum | The greatest value in a collection. |
| Minimum | The least value in a collection. |
| Palindrome number | A number that reads the same from left to right and right to left. |
| Perfect number | A positive integer equal to the sum of its positive divisors excluding itself. |
| Prime factor | A prime number that divides another number. |
| Prime number | A positive integer greater than 1 with exactly two positive divisors. |
| Proper divisor | A divisor of a number other than the number itself. |
| Sentinel-controlled input | Input that ends when a special stopping value is entered. |
Question bank
Short Answer Questions (2 marks each)
- Which two operations are used to extract the last digit of a number and to remove it?
- Define a palindrome number with an example.
- Why is 1 not a prime number?
- Define a perfect number and give two examples.
- What are amicable numbers? Give one pair.
- Define an Armstrong number with an example.
- What is the value of 0! and why does the factorial product start at 1?
- Convert the binary number 1011 to decimal.
- What is the difference between ++i and i++?
- Distinguish between break and continue.
Medium Answer Questions (5 marks each)
- Write an algorithm and a C program to find the sum of the digits of a number.
- Draw a flowchart and write a C program to check whether a number is a palindrome.
- Explain why testing divisors up to the square root of n is sufficient for a prime test, and write the program.
- Explain the method of converting a decimal number to binary with an example, and the need to validate digits.
- Write a C program using sentinel-controlled input to find the maximum, minimum and average of a set of marks.
- Compare the else-if ladder and the switch statement with examples.
Long Answer Questions (15 marks each)
- Explain digit extraction from right to left and from left to right. Write C programs to check whether a number is a palindrome and whether it is an Armstrong number, and trace each for one input.
- Define prime numbers, prime factors, perfect numbers and amicable numbers. Write algorithms and C programs to test a number for primality, to display its prime factors and to test an amicable pair.
- Explain number-base conversion in detail. Write a C program that validates a number against its base, converts it to decimal and then to binary, and trace it for the octal number 157.
- Explain multiple-way selection in C using the else-if ladder and the switch statement. Discuss the increment and decrement operators and the break and continue statements with suitable programs.
Sources
- Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit III
