Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

VNSGU BCA Sem 2: Programming Skills (204) Practical Solutions - April 2024 Set B

Paper Details
  • Subject: Programming Skills Using C
  • Subject Code: 204
  • Set: B
  • Semester: 2
  • Month/Year: April 2024
  • Max Marks: 25
  • Time Recommendation: 2 Hours
  • Paper: View Paper | Download PDF

Questions & Solutions​

All questions are compulsory​

Q1: Armstrong Number Check​

Max Marks: 20

Write a Python program to check whether the number is Armstrong or Not.

Hint

An Armstrong number is a number that is equal to the sum of cubes of its digits. For example, 153 = 1Β³ + 5Β³ + 3Β³ = 1 + 125 + 27 = 153.

Solution Approach​

Solution - Python
def is_armstrong(number):
"""Check if a number is Armstrong number."""
original = number
sum_of_cubes = 0

# Calculate sum of cubes of digits
while number > 0:
digit = number % 10
sum_of_cubes += digit ** 3
number //= 10

return original == sum_of_cubes

# Main program
if __name__ == "__main__":
try:
# Get input from user
num = int(input("Enter a number: "))

if num < 0:
print("Please enter a positive number.")
else:
# Check and display result
if is_armstrong(num):
print(f"{num} is an Armstrong number!")

# Show calculation
print("\nCalculation:")
temp = num
calc_str = ""
while temp > 0:
digit = temp % 10
if calc_str:
calc_str = f"{digit}Β³ + " + calc_str
else:
calc_str = f"{digit}Β³"
temp //= 10
print(f"{calc_str}")
else:
print(f"{num} is NOT an Armstrong number.")

except ValueError:
print("Invalid input! Please enter a valid integer.")

Sample Output 1:

Enter a number: 153
153 is an Armstrong number!

Calculation:
1Β³ + 5Β³ + 3Β³

Sample Output 2:

Enter a number: 123
123 is NOT an Armstrong number.
Alternative: For n-digit Armstrong Numbers

The above solution works for 3-digit Armstrong numbers. For a general n-digit Armstrong number, use this approach:

def is_armstrong_general(number):
"""Check if a number is Armstrong number (general n-digit version)."""
original = number
digits = str(number)
n = len(digits)
sum_of_powers = 0

for digit in digits:
sum_of_powers += int(digit) ** n

return original == sum_of_powers

# Test with various Armstrong numbers
test_numbers = [153, 370, 371, 407, 1634, 8208, 9474]

for num in test_numbers:
result = "Armstrong" if is_armstrong_general(num) else "Not Armstrong"
print(f"{num}: {result}")
Alternative: Using List Comprehension
def is_armstrong_compact(number):
"""Compact version using list comprehension."""
digits = [int(d) for d in str(number)]
n = len(digits)
return sum(d ** n for d in digits) == number

# Main
num = int(input("Enter a number: "))
print(f"{num} is {'an' if is_armstrong_compact(num) else 'not an'} Armstrong number")

Q2: Viva Preparation​

Max Marks: 5

Potential Viva Questions
  1. Q: What is an Armstrong number?
    • A: A number equal to the sum of cubes of its digits (or nth power for n-digit numbers).
  2. Q: Why use // instead of / in Python?
    • A: // is integer division (floor division), / returns float.
  3. Q: What is the purpose of ** operator?
    • A: It is the exponentiation operator (e.g., digit ** 3 means digitΒ³).
  4. Q: How do you reverse a number in Python?
    • A: Use modulo % to get last digit and integer division // to remove it.
  5. Q: What are some Armstrong numbers?
    • A: 0, 1, 153, 370, 371, 407 are 3-digit Armstrong numbers.
Common Pitfalls
  • Single Digit: Remember 0-9 are all Armstrong numbers (1^n = 1).
  • Negative Numbers: Armstrong numbers are defined for positive integers only.
  • Type Conversion: Use int() when converting string input to number.

Quick Navigation​

SetLink
Set ASolutions
Set BCurrent Page
Set CSolutions
Set DSolutions
Set ESolutions
Set FSolutions

Last Updated: April 2026

πŸ“ Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
πŸ“ Address
2/66 Faram Street, Rustompura
Surat – 395002, Gujarat, India
πŸ“ž Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition β€” Areas We Serve in Surat

Adajanβ€’Althanβ€’Amroliβ€’Athwaβ€’Athwalinesβ€’Bhagalβ€’Bhatarβ€’Bhestanβ€’Canal Roadβ€’Chowkβ€’Citylightβ€’Dumasβ€’Gaurav Pathβ€’Ghod Dod Roadβ€’Haziraβ€’Jahangirpuraβ€’Kamrejβ€’Kapodraβ€’Katargamβ€’Limbayatβ€’Magdallaβ€’Majura Gateβ€’Mota Varachhaβ€’Nanpuraβ€’New Citylightβ€’Olpadβ€’Palβ€’Pandesaraβ€’Parle Pointβ€’Piplodβ€’Punaβ€’Randerβ€’Ring Roadβ€’Rustampuraβ€’Sachinβ€’Salabatpuraβ€’Sarthanaβ€’Sosyo Circleβ€’Udhnaβ€’Varachhaβ€’Ved Roadβ€’Vesuβ€’VIP Road
πŸ“ž Call SirπŸ’¬ WhatsApp Sir