0% found this document useful (0 votes)
6 views2 pages

LAB TASK Dsa

The document outlines algorithms for various mathematical tasks including calculating the factorial of a number, finding the average of three subjects, checking if a character is a vowel or consonant, determining leap years, verifying if a character is an alphabet, and finding the least common multiple (LCM) of two numbers. Each algorithm includes steps for input, processing, and output. The document serves as a guide for implementing these algorithms in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

LAB TASK Dsa

The document outlines algorithms for various mathematical tasks including calculating the factorial of a number, finding the average of three subjects, checking if a character is a vowel or consonant, determining leap years, verifying if a character is an alphabet, and finding the least common multiple (LCM) of two numbers. Each algorithm includes steps for input, processing, and output. The document serves as a guide for implementing these algorithms in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LAB TASK

Write an algorithm to calculate the factorial of a given number.

Input a number n from the user.


Initialize a variable r = 1 (this will store the factorial result).
Loop from i = 1 to n:
Multiply r by i → r = r * i
Output the value of r as the factorial of n

Write an algorithm to find the average of 3 subjects.

Take input marks of three subjects: sub1, sub2, sub3.


Calculate sum: SUM = sub1 + sub2 + sub3.
Initialize TOTALSUB = 3 (since there are 3 subjects).
Calculate average: AVERAGE = SUM / TOTALSUB.
Print the AVERAGE.

Write an algorithm to check whether a character is a vowel or a


consonant.
Take input a character char from the user.
Initialize a list (or set) vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I',
'O', 'U'}.
Check if char is an alphabet (i.e., between 'A'-'Z' or 'a'-'z'):
If yes, check:
If char is in vowels, print "Vowel".
Else, print "Consonant".
If no, print "Not an alphabet"
Write an algorithm to check the leap year.
Take input year from the user.
Check the conditions:
If the year is divisible by 400, print "Leap Year".
Else if year is divisible by 100, print "Not a Leap Year".
Else if year is divisible by 4, print "Leap Year".
Otherwise, print "Not a Leap Year".

Write an algorithm to check whether a character is an alphabet or


not.
Take input a character char from the user.
Check if char is an alphabet:
If char is between 'A' and 'Z' OR between 'a' and 'z', print
"Alphabet".
Otherwise, print "Not an alphabet".

Write an algorithm and a program to find the LCM of two numbers.

Input: Two numbers a and b.


Initialize lcm = 1 and divisor = 2.
While a or b is greater than 1`:
If a is divisible by divisor, divide a by divisor.
If b is divisible by divisor, divide b by divisor.
Multiply lcm by divisor.
If neither a nor b is divisible, increase divisor to the next
prime number.
Output lcm as the Least Common Multiple.

You might also like