Tutorial : following are the excercises for the students to practice writing
algorthms and drawing flow charts.
Exercise 1: Simple Calculator
Problem: Write an algorithm and draw a flowchart to create a simple calculator that
can perform addition, subtraction, multiplication, and division of two numbers.
Instructions:
1. Input two numbers.
2. Ask the user to choose an operation (+, -, *, /).
3. Perform the selected operation.
4. Display the result.
Exercise 2: Odd or Even
Problem: Write an algorithm and draw a flowchart to determine whether a given
number is odd or even.
Instructions:
1. Input a number.
2. Check if the number is divisible by 2.
3. If divisible, print "Even".
4. If not divisible, print "Odd".
Exercise 3: Largest of Three Numbers
Problem: Write an algorithm and draw a flowchart to find the largest of three
numbers.
Instructions:
1. Input three numbers.
2. Compare the numbers to find the largest.
3. Print the largest number.
Exercise 4: Factorial of a Number
Problem: Write an algorithm and draw a flowchart to calculate the factorial of a
given number.
Instructions:
1. Input a number.
2. Initialize a variable to store the factorial result.
3. Use a loop to multiply the numbers from 1 to the given number.
4. Print the factorial result.
Exercise 5: Prime Number Check
Problem: Write an algorithm and draw a flowchart to check if a given number is a
prime number.
Instructions:
1. Input a number.
2. Check if the number is divisible by any number other than 1 and itself.
3. If divisible, print "Not Prime".
4. If not divisible, print "Prime".
Exercise 6: Sum of Natural Numbers
Problem: Write an algorithm and draw a flowchart to calculate the sum of the first N
natural numbers.
Instructions:
1. Input a number N.
2. Initialize a variable to store the sum.
3. Use a loop to add numbers from 1 to N.
4. Print the sum.
Exercise 7: Reverse a Number
Problem: Write an algorithm and draw a flowchart to reverse a given number.
Instructions:
1. Input a number.
2. Use a loop to reverse the digits of the number.
3. Print the reversed number.
Exercise 8: Fibonacci Series
Problem: Write an algorithm and draw a flowchart to generate the first N terms of
the Fibonacci series.
Instructions:
1. Input a number N.
2. Initialize the first two terms of the series (0 and 1).
3. Use a loop to generate the next terms by summing the previous two terms.
4. Print the series.
Exercise 9: Palindrome Check
Problem: Write an algorithm and draw a flowchart to check if a given string is a
palindrome.
Instructions:
1. Input a string.
2. Reverse the string.
3. Compare the original string with the reversed string.
4. If they match, print "Palindrome".
5. If they don't match, print "Not Palindrome".
Exercise 10: Grade Calculator
Problem: Write an algorithm and draw a flowchart to calculate the grade of a
student based on their marks in five subjects.
Instructions:
1. Input marks for five subjects.
2. Calculate the average marks.
3. Use the following grading system:
o A: 90-100
o B: 80-89
o C: 70-79
o D: 60-69
o F: Below 60
4. Print the grade.
Exercise 11: Temperature Conversion
Problem: Write an algorithm and draw a flowchart to convert temperature from
Celsius to Fahrenheit and vice versa.
Instructions:
1. Ask the user to choose the conversion type (Celsius to Fahrenheit or
Fahrenheit to Celsius).
2. Input the temperature.
3. Perform the conversion using the appropriate formula:
o Celsius to Fahrenheit: F=(C×9/5)+32F=(C×9/5)+32
o Fahrenheit to Celsius: C=(F−32)×5/9C=(F−32)×5/9
4. Print the converted temperature.
Exercise 12: Leap Year Check
Problem: Write an algorithm and draw a flowchart to check if a given year is a leap
year.
Instructions:
1. Input a year.
2. Check if the year is divisible by 4 but not by 100, or if it is divisible by 400.
3. If it meets the conditions, print "Leap Year".
4. Otherwise, print "Not a Leap Year".
Exercise 13: Count Vowels in a String
Problem: Write an algorithm and draw a flowchart to count the number of vowels in
a given string.
Instructions:
1. Input a string.
2. Initialize a counter for vowels.
3. Check each character in the string to see if it is a vowel (a, e, i, o, u).
4. Increment the counter for each vowel found.
5. Print the total count of vowels.
Exercise 14: Find the Second Largest Number
Problem: Write an algorithm and draw a flowchart to find the second largest
number in a list of numbers.
Instructions:
1. Input a list of numbers.
2. Find the largest number in the list.
3. Find the second largest number by excluding the largest number.
4. Print the second largest number.
Exercise 15: Password Validation
Problem: Write an algorithm and draw a flowchart to validate a password based on
the following rules:
• The password must be at least 8 characters long.
• The password must contain at least one uppercase letter, one lowercase letter,
and one digit.
Instructions:
1. Input a password.
2. Check if the password meets the length requirement.
3. Check if the password contains at least one uppercase letter, one lowercase
letter, and one digit.
4. If all conditions are met, print "Valid Password".
5. Otherwise, print "Invalid Password".