Set A . Write C programs for the following problems.
1. Write a program to display all prime numbers between ____ and ____.
2. Write a program to display multiplication tables from ___ to ___ having n multiples each. The output should be displayed in a tabular format. For example, the multiplication tables of 2 to 9 having 10 multiples each is shown below.
2 × 1 = 2 3 × 1 = 3 ………….9 × 1 = 9
2 × 2 = 4 3 × 2 = 6…………..9 × 2 = 18
…………. …………. .................................
2 × 10 = 20 3 × 10 = 30………..9 × 10 = 90
3. Modify the sample program 1 to display n lines as follows (here n=4).
A B C D
E F G
H I
J
Set B. Write C programs for the following problems.
1. Write a program to display all Armstrong numbers between 1 and 500. (An Armstrong number is a number such that the sum of cube of digits = number itself Ex. 153 = 1*1*1 + 5*5*5+ 3*3*3
2. Accept n numbers and display the number having the maximum sum of digits
3.Display all perfect numbers below 500[A perfect number is a number, such that the sum of its factors is equal to the number itself]. Example: 6 (1 + 2 + 3), 28 (1+2+4+7+14)
1. Write a program to display all prime numbers between ____ and ____.
2. Write a program to display multiplication tables from ___ to ___ having n multiples each. The output should be displayed in a tabular format. For example, the multiplication tables of 2 to 9 having 10 multiples each is shown below.
2 × 1 = 2 3 × 1 = 3 ………….9 × 1 = 9
2 × 2 = 4 3 × 2 = 6…………..9 × 2 = 18
…………. …………. .................................
2 × 10 = 20 3 × 10 = 30………..9 × 10 = 90
3. Modify the sample program 1 to display n lines as follows (here n=4).
A B C D
E F G
H I
J
Set B. Write C programs for the following problems.
1. Write a program to display all Armstrong numbers between 1 and 500. (An Armstrong number is a number such that the sum of cube of digits = number itself Ex. 153 = 1*1*1 + 5*5*5+ 3*3*3
2. Accept n numbers and display the number having the maximum sum of digits
3.Display all perfect numbers below 500[A perfect number is a number, such that the sum of its factors is equal to the number itself]. Example: 6 (1 + 2 + 3), 28 (1+2+4+7+14)

3 Comments
class BankAccount:
ReplyDeletedef __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
def deposit(self, amount):
self.balance = self.balance + amount
print("Deposited",amount , "New balance:", self.balance)
def withdraw(self, amount):
self.balance = self.balance - amount
print("Withdrew", amount, "New balance: ",self.balance)
def check_balance(self):
print("Current balance: ", self.balance)
return self.balance
account = BankAccount("Alice", 100)
account.check_balance()
account.deposit(50)
account.withdraw(30)
account.withdraw(200)
account.check_balance()
# Program to perform division with user input and exception handling
ReplyDeletewhile(True):
try:
numerator = float(input("Enter the numerator: "))
denominator = float(input("Enter the denominator: "))
result = numerator / denominator
except ValueError:
print("Error: Please enter valid numbers only.")
except ZeroDivisionError:
print("Error: Division by zero is not allowed.")
else:
print(f"The result of division is: {result:.2f}")
finally:
print("Program execution completed. \n")
# Program to perform division with user input and exception handling
ReplyDeleteclass NegativeDenominatorError(Exception):
"""Custom exception raised when the denominator is negative."""
pass
while(True):
try:
numerator = float(input("Enter the numerator: "))
denominator = float(input("Enter the denominator: "))
if denominator <= 0:
raise NegativeDenominatorError("Error: Denominator cannot be negative! and cannot be zero itself")
result = numerator / denominator
except NegativeDenominatorError as e:
print(e)
else:
print(f"The result of division is: {result:.2f}")
finally:
print("Program execution completed. \n")