Set A . Apply all the three program development steps for the following examples.
1. Write a program to accept an integer n and display all even numbers upto n.
2. Accept two integers x and y and calculate the sum of all integers between x and y (both inclusive)
3. Write a program to accept two integers x and n and compute x^n
4. Write a program to accept an integer and check if it is prime or not.
5. Write a program to accept an integer and count the number of digits in the number.
6. Write a program to accept an integer and reverse the number. Example: Input: 546, Output 645.
7. Write a program to accept a character, an integer n and display the next n characters.
Set B. Apply all the three program development steps for the following examples.
1. Write a program to display the first n Fibonacci numbers. (1 1 2 3 5 ……)
2. Write a program to accept real number x and integer n and calculate the sum of first n terms of the series x+ 3x+5x+7x+…
3. Write a program to accept real number x and integer n and calculate the sum of first n terms of the series 1/x + 2/x^2 + 3/x^3 + …
4. Write a program to accept characters till the user enters EOF and count number of alphabets and digits entered.
5. Write a program, which accepts a number n and displays each digit in words. Example: 6702 Output = Six-Seven-Zero-Two. (Hint: Reverse the number and use a switch statement)
Set C. Write C programs to solve the following problems
1. Write a program which accepts a number and checks if the number is a palindrome (Hint number = reverse of number)
Example:Input :3472
Output : It is not a palindrome number
Input :262,
Output : It is a palindrome
1. Write a program to accept an integer n and display all even numbers upto n.
2. Accept two integers x and y and calculate the sum of all integers between x and y (both inclusive)
3. Write a program to accept two integers x and n and compute x^n
4. Write a program to accept an integer and check if it is prime or not.
5. Write a program to accept an integer and count the number of digits in the number.
6. Write a program to accept an integer and reverse the number. Example: Input: 546, Output 645.
7. Write a program to accept a character, an integer n and display the next n characters.
Set B. Apply all the three program development steps for the following examples.
1. Write a program to display the first n Fibonacci numbers. (1 1 2 3 5 ……)
2. Write a program to accept real number x and integer n and calculate the sum of first n terms of the series x+ 3x+5x+7x+…
3. Write a program to accept real number x and integer n and calculate the sum of first n terms of the series 1/x + 2/x^2 + 3/x^3 + …
4. Write a program to accept characters till the user enters EOF and count number of alphabets and digits entered.
5. Write a program, which accepts a number n and displays each digit in words. Example: 6702 Output = Six-Seven-Zero-Two. (Hint: Reverse the number and use a switch statement)
Set C. Write C programs to solve the following problems
1. Write a program which accepts a number and checks if the number is a palindrome (Hint number = reverse of number)
Example:Input :3472
Output : It is not a palindrome number
Input :262,
Output : It is a palindrome

3 Comments
There are no answers for
ReplyDeleteset c 2,3
#write a class bank account with deposit, withdraw, and balance cheking method
ReplyDeleteclass BankAccount:
def __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"Deposited {amount:.2f}. New balance: {self.balance:.2f}")
else:
print("Deposit amount must be positive!")
def withdraw(self, amount):
if amount <= 0:
print("Withdrawal amount must be positive!")
elif amount > self.balance:
print("Insufficient funds!")
else:
self.balance -= amount
print(f"Withdrew {amount:.2f}. New balance: {self.balance:.2f}")
def check_balance(self):
print(f"Current balance: {self.balance:.2f}")
return self.balance
account = BankAccount("Alice", 100)
account.check_balance()
account.deposit(50)
account.withdraw(30)
account.withdraw(200)
account.check_balance()
#write vehicle base class and car and motorcycle subclass demonstrating method overloding
ReplyDeleteclass Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def start_engine(self):
print(f"The engine of {self.brand} {self.model} starts with a generic key.")
def display_info(self):
print(f"Vehicle: {self.brand} {self.model}")
class Car(Vehicle):
def __init__(self, brand, model, doors):
super().__init__(brand, model)
self.doors = doors
def start_engine(self):
print(f"The {self.brand} {self.model} starts with a push-button ignition.")
def display_info(self):
print(f"Car: {self.brand} {self.model} with {self.doors} doors.")
class Motorcycle(Vehicle):
def __init__(self, brand, model, type_of_bike):
super().__init__(brand, model)
self.type_of_bike = type_of_bike
def start_engine(self):
print(f"The {self.brand} {self.model} motorcycle starts with a kick or electric start.")
def display_info(self):
print(f"Motorcycle: {self.brand} {self.model} ({self.type_of_bike})")
v = Vehicle("Generic", "ModelX")
v.start_engine()
v.display_info()
print("\n--- Car ---")
c = Car("Toyota", "Camry", 4)
c.start_engine()
c.display_info()
print("\n--- Motorcycle ---")
m = Motorcycle("Yamaha", "MT-15", "Sport")
m.start_engine()
m.display_info()