0% found this document useful (0 votes)
39 views1 page

Algorithm Challenges for Beginners

This document contains 5 questions asking to write algorithms to: 1) Determine if candies can be divided evenly between two people 2) Determine if a given year is a leap year 3) Determine if a triangle can be formed from three given side lengths 4) Calculate the factorial of a given number 5) Count from 1 to 20 and print only numbers divisible by 3.

Uploaded by

Hosef
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)
39 views1 page

Algorithm Challenges for Beginners

This document contains 5 questions asking to write algorithms to: 1) Determine if candies can be divided evenly between two people 2) Determine if a given year is a leap year 3) Determine if a triangle can be formed from three given side lengths 4) Calculate the factorial of a given number 5) Count from 1 to 20 and print only numbers divisible by 3.

Uploaded by

Hosef
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/ 1

1 Questions

1. Candy Sharing: Alice and Bob have a bag of candies. They want to share the candies equally between
them. Write an algorithm to determine if it is possible to divide the candies evenly, assuming they can
only split the candies into whole numbers. Print “YES” if possible, and “NO” otherwise.

2. Leap Year: Write an algorithm to determine if a given year is a leap year. Print “YES” if it is a leap
year, and “NO” otherwise. (Hint: A leap year is divisible by 4 but not divisible by 100, unless it is also
divisible by 400.)

3. Triangle Inequality: Given the lengths of three sides of a triangle, write an algorithm to determine if a
triangle can be formed using those side lengths. Print “YES” if a triangle can be formed, and “NO”
otherwise. (Hint: In a triangle, the sum of the lengths of any two sides must be greater than the length
of the third side.)

4. Factorial: Write an algorithm to calculate the factorial of a given number. The factorial of a number n is
the product of all positive integers from 1 to n. Print the factorial as the output.

5. Counting in Multiples: Write an algorithm to count from 1 to 20, but only print the numbers that are
multiples of 3.

You might also like