Loops Programs

EXACT OUTPUT IS OPTIONAL FOR PYTHON AND JAVASCRIPT

WAP to read a number and print all numbers from 1 to that number

Input: Enter a number: 5
Output:
1
2
3
4
5

WAP to read number and print all even numbers from 1 to that number

Input: Enter a number: 5
Output:
2
4

WAP to print all numbers from 1 to 10 using while, for, and do-while loop


WAP to read a number and find sum of all numbers from 1 to that number

Input: Enter a number: 5
Output: 1 + 2 + 3 + 4 + 5 = 15

WAP to read a number and find factorial of that number

Input: Enter a number: 5
Output: 1 * 2 * 3 * 4 * 5 = 120

WAP to read a number and check if it is a prime number or not

Input: Enter a number: 5
Output: 5 is a prime number

WAP to print all prime numbers in range from 1 to 100

Output:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67,
71, 73, 79, 83, 89, 97

WAP to print first 10 Fibonacci numbers

Output: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55

WAP to print table of number in following format using 1 for loop

Input: Enter a number: 5
Output:
5 * 1 = 5     5 * 10 = 50
5 * 2 = 10    5 * 9 = 45
5 * 3 = 15    5 * 8 = 40
5 * 4 = 20    5 * 7 = 35
5 * 5 = 25    5 * 6 = 30
5 * 6 = 30    5 * 5 = 25
5 * 7 = 35    5 * 4 = 20
5 * 8 = 40    5 * 3 = 15
5 * 9 = 45    5 * 2 = 10
5 * 10 = 50   5 * 1 = 5

WAP to create random jackpot number and take input from user to guess the number

  • Based on level, the attempt to guess the number should change:

    • Easy – 20 attempts

    • Medium – 10 attempts

    • Difficult – 5 attempts


WAP to execute Fizz Buzz Problem / Print number 1 to 100

  • If number is divisible by 3 then print Fizz

  • If number is divisible by 5 then print Buzz

  • If number is divisible by both 3 and 5 then print Fizz Buzz

Leave a Reply

Your email address will not be published. Required fields are marked *