1.
Factorial Program
Algorithm
Start.
Input: Prompt the user to enter a number.
Initialize: Set fact = 1.
Loop:
For each integer i from 1 to the input number:
Multiply fact by i (i.e. fact = fact * i).
Output: Display the value of fact.
End.
2. Fibonacci Series
Algorithm
Start.
Input: Prompt the user to enter the number of terms (n).
Initialize:
Set a = 0 and b = 1.
Output: Print the first two numbers (a and b).
Loop:
For i from 2 to n–1:
Compute c = a + b.
Print c.
Update: set a = b and b = c.
End.
3. Conditional Statements
Algorithm
Start.
Input: Prompt the user to enter a number.
Decision:
If the number is greater than 0, then print "Positive
Number".
Else if the number is less than 0, then print "Negative
Number".
Else print "Zero".
End.
4. Looping Statements
Algorithm
Start.
Loop:
For i from 1 to 5:
Print "Iteration: " followed by the value of i.
End.
5. Class and Object Demonstration
Algorithm
Start.
Define:
A class with an instance variable x = 10.
In Main:
Create an object of the class.
Access the object's variable x.
Output: Print the value of x.
End.
6. Method Overloading
Algorithm
Start.
Define:
Two methods named display – one that accepts an
integer and one that accepts a double.
In Main:
Create an object of the class.
Call display with an integer value.
Call display with a double value.
Output:
The integer and double values are printed by their
respective method calls.
End.
7. Constructors
Algorithm
Start.
Define:
A class that includes a constructor which prints a
message when called.
In Main:
Create an object of the class (which automatically calls
the constructor).
Output: The constructor prints "Constructor Called".
End.
8. Inheritance
Algorithm
Start.
Define Parent Class:
Create a class with a method show() that prints "Parent
Class".
Define Child Class:
Inherit from the Parent class.
Create an additional method display() that prints "Child
Class".
In Main (Child class):
Create an object of the Child class.
Call the inherited show() method.
Call the display() method.
End.
9. Method Overriding
Algorithm
Start.
Define SuperClass:
Create a class with a method show() that prints
"SuperClass Method".
Define SubClass:
Inherit from SuperClass.
Override the show() method to print "SubClass Method".
In Main:
Create an object of SubClass (using a SuperClass
reference).
Call the show() method.
Output: "SubClass Method" is printed.
End.
10. Arrays
Algorithm
Start.
Initialize:
Declare an array with elements [10, 20, 30, 40, 50].
Loop:
For each element in the array:
Print the element.
End.