For While Dowhile
For While Dowhile
Task 10: Print prime numbers in a given range using a for loop
Objective: Print all prime numbers in a given range using a for loop.
Task: Input two numbers start and end, and print all prime numbers between them.
Logic: Use a nested for loop to check for primes in the range and print them.
Task: Input a number N and print an inverted right triangle of stars of size N.
Logic: Use a for loop to print stars, reducing the number of stars each row.
Task 22: Find the number of divisors of a number using a for loop
Objective: Find how many divisors a number has using a for loop.
Task: Input a number n and calculate how many divisors n has.
Logic: Use a for loop to check each number from 1 to n if it divides n without a remainder.
Task 30: Merge two sorted arrays into one sorted array
Objective: Merge two sorted arrays into one sorted array.
Task: Input two sorted arrays and merge them into a single sorted array.
Logic: Use two for loops to compare the elements of both arrays and add them in sorted order.
6
Task 36: Print the multiplication table of a number using a while loop
Objective: Print the multiplication table of a given number using a while loop.
Task: Input a number n and print its multiplication table from 1 to 10.
Logic: Initialize a counter variable i = 1 and use a while loop to multiply n by i and print the
result.
Task 37: Print a pattern of stars in a square shape using a while loop
Objective: Print a square-shaped pattern of stars using a while loop.
Task: Input a number N and print a square of stars of size N.
Logic: Use a while loop to print stars in each row and use another while loop to print N rows.
Task 42: Find the sum of digits of a number using a while loop
Objective: Calculate the sum of digits of a given number using a while loop.
Task: Input a number n and calculate the sum of its digits.
Logic: Use a while loop to extract each digit and add it to the sum using modulo.
Task 43: Print all prime numbers in a range using a while loop
Objective: Print all prime numbers in a given range using a while loop.
Task: Input two numbers start and end, and print all prime numbers between them.
Logic: Use a while loop to check for primes in the range and print them.
Task 44: Find the sum of all even numbers from 1 to N using a while loop
Objective: Calculate the sum of all even numbers from 1 to N using a while loop.
Task: Input a number N and calculate the sum of all even numbers from 1 to N.
Logic: Initialize i = 2 and use a while loop to sum even numbers from 2 to N.
Task 46: Find the number of digits in a number using a while loop
Objective: Find the number of digits in a given number using a while loop.
Task: Input a number n and find how many digits it has.
Logic: Use a while loop to divide the number by 10 until it becomes 0, counting the number of
divisions.
Task 48: Find the largest element in an array using a while loop
Objective: Find the largest element in an array using a while loop.
Task: Input an array and find the largest element.
Logic: Initialize a variable max and use a while loop to compare each element to find the
maximum value.
Task 49: Count the number of even numbers in an array using a while loop
Objective: Count how many even numbers are present in an array using a while loop.
Task: Input an array and count the number of even numbers.
Logic: Use a while loop to check if each element is even and increment the counter
accordingly.
Task 51: Find the smallest element in an array using a while loop
Objective: Find the smallest element in an array using a while loop.
Task: Input an array and find the smallest element.
Logic: Initialize a variable min and use a while loop to compare each element to find the
minimum value.
Task 52: Find the sum of odd numbers in an array using a while loop
Objective: Find the sum of odd numbers in an array using a while loop.
Task: Input an array and calculate the sum of its odd numbers.
Logic: Use a while loop to check if each number is odd and add it to the sum.
Task 53: Print a half-pyramid pattern using stars with a while loop
Objective: Print a half-pyramid pattern using stars with a while loop.
Task: Input a number N and print a half-pyramid pattern of stars.
Logic: Use a while loop to print rows with increasing stars.
10
Task 55: Find the sum of diagonal elements in a matrix using a while loop
Objective: Find the sum of diagonal elements in a matrix.
Task: Input a square matrix and calculate the sum of its diagonal elements.
Logic: Use a while loop to access diagonal elements and sum them.
Task 57: Print prime numbers in a given range using a while loop
Objective: Print prime numbers in a given range using a while loop.
Task: Input two numbers start and end, and print all prime numbers in the range.
Logic: Use a while loop to check each number in the range for primality and print the prime
numbers.
Task 58: Count the number of odd numbers in an array using a while loop
Objective: Count the number of odd numbers in an array using a while loop.
Task: Input an array and count how many odd numbers it contains.
Logic: Use a while loop to check each element and increment the counter if the element is
odd.
Task 59: Find the average of elements in an array using a while loop
Objective: Calculate the average of elements in an array using a while loop.
Task: Input an array and calculate its average.
Logic: Sum the elements using a while loop and divide by the total number of elements.
11
Task 60: Print a diamond pattern using stars with a while loop
Objective: Print a diamond pattern using stars with a while loop.
Task: Input a number N and print a diamond-shaped pattern using stars.
Logic: Use while loops to print both the upper and lower parts of the diamond shape.
Task 63: Print the multiplication table of a number using a do-while loop
Objective: Print the multiplication table of a given number using a do-while loop.
Task: Input a number n and print its multiplication table from 1 to 10.
Logic: Initialize a counter variable i = 1 and use a do-while loop to multiply n by i and print the
result.
Task 64: Print a pattern of stars in a square shape using a do-while loop
Objective: Print a square-shaped pattern of stars using a do-while loop.
Task: Input a number N and print a square of stars of size N.
Logic: Use a do-while loop to print stars in each row and use another do-while loop to print N
rows.
12
Task 69: Find the sum of digits of a number using a do-while loop
Objective: Calculate the sum of digits of a given number using a do-while loop.
Task: Input a number n and calculate the sum of its digits.
Logic: Use a do-while loop to extract each digit and add it to the sum using modulo.
Task 70: Print all prime numbers in a range using a do-while loop
Objective: Print all prime numbers in a given range using a do-while loop.
Task: Input two numbers start and end, and print all prime numbers between them.
Logic: Use a do-while loop to check for primes in the range and print them.
13
Task 71: Find the sum of all even numbers from 1 to N using a do-while loop
Objective: Calculate the sum of all even numbers from 1 to N using a do-while loop.
Task: Input a number N and calculate the sum of all even numbers from 1 to N.
Logic: Initialize i = 2 and use a do-while loop to sum even numbers from 2 to N.
Task 73: Find the number of digits in a number using a do-while loop
Objective: Find the number of digits in a given number using a do-while loop.
Task: Input a number n and find how many digits it has.
Logic: Use a do-while loop to divide the number by 10 until it becomes 0, counting the number
of divisions.
Task 75: Find the largest element in an array using a do-while loop
Objective: Find the largest element in an array using a do-while loop.
Task: Input an array and find the largest element.
Logic: Initialize a variable max and use a do-while loop to compare each element to find the
maximum value.
Task 76: Count the number of even numbers in an array using a do-while loop
Objective: Count how many even numbers are present in an array using a do-while loop.
Task: Input an array and count the number of even numbers.
Logic: Use a do-while loop to check if each element is even and increment the counter
accordingly.
14
Task 78: Find the smallest element in an array using a do-while loop
Objective: Find the smallest element in an array using a do-while loop.
Task: Input an array and find the smallest element.
Logic: Initialize a variable min and use a do-while loop to compare each element to find the
minimum value.
Task 79: Find the sum of odd numbers in an array using a do-while loop
Objective: Find the sum of odd numbers in an array using a do-while loop.
Task: Input an array and calculate the sum of its odd numbers.
Logic: Use a do-while loop to check if each number is odd and add it to the sum.
Task 80: Print a half-pyramid pattern using stars with a do-while loop
Objective: Print a half-pyramid pattern using stars with a do-while loop.
Task: Input a number N and print a half-pyramid pattern of stars.
Logic: Use a do-while loop to print rows with increasing stars.
Task 82: Find the sum of diagonal elements in a matrix using a do-while loop
Objective: Find the sum of diagonal elements in a matrix.
Task: Input a square matrix and calculate the sum of its diagonal elements.
Logic: Use a do-while loop to access diagonal elements and sum them.
15
Task 84: Count the occurrences of a specific number in an array using a do-while loop
Objective: Count how many times a specific number appears in an array.
Task: Input an array and a target number. Count how many times the target number appears in
the array.
Logic: Use a do-while loop to check each element of the array and increment the counter if
the element matches the target.
Task 87: Count the number of negative numbers in an array using a do-while loop
Objective: Count how many negative numbers are in an array.
Task: Input an array and count how many numbers are negative.
Logic: Use a do-while loop to check each element of the array for negativity.
Task 88: Find the sum of squares of all numbers from 1 to N using a do-while loop
Objective: Calculate the sum of squares of numbers from 1 to N.
Task: Input a number N and calculate the sum of squares of all numbers from 1 to N.
Logic: Use a do-while loop to square each number and add it to the sum.
16
Task 89: Check if a number is divisible by both 3 and 5 using a do-while loop
Objective: Check if a given number is divisible by both 3 and 5.
Task: Input a number and check if it is divisible by both 3 and 5.
Logic: Use a do-while loop to check divisibility with the modulo operator.
Task 92: Find the sum of odd numbers between two given numbers using a do-while loop
Objective: Calculate the sum of odd numbers between two given numbers.
Task: Input two numbers and find the sum of odd numbers between them.
Logic: Use a do-while loop to check each number for oddness and sum them.
Task 93: Print a half-diamond pattern using numbers with a do-while loop
Objective: Print a half-diamond pattern using numbers.
Task: Input a number N and print a half-diamond pattern using numbers.
Logic: Use a do-while loop to print increasing numbers in the upper half and decreasing in the
lower half.
Task 95: Print a right-angled triangle pattern using stars with a do-while loop
Objective: Print a right-angled triangle pattern using stars.
Task: Input a number N and print a right-angled triangle of stars.
Logic: Use a do-while loop to print stars, increasing by one on each row.
Task 96: Print the sum of all multiples of 3 from 1 to N using a do-while loop
Objective: Calculate the sum of all multiples of 3 from 1 to N.
Task: Input a number N and calculate the sum of all multiples of 3.
Logic: Use a do-while loop to check each number for divisibility by 3 and sum them.
Task 97: Count the number of vowels in a string using a do-while loop
Objective: Count the number of vowels in a given string.
Task: Input a string and count the number of vowels it contains.
Logic: Use a do-while loop to iterate through the string and check for vowels.
Task 98: Print a diamond pattern using numbers with a do-while loop
Objective: Print a diamond pattern using numbers.
Task: Input a number N and print a diamond pattern using numbers.
Logic: Use a do-while loop to print both the upper and lower parts of the diamond with
numbers.
Task 99: Calculate the product of all even numbers from 1 to N using a do-while loop
Objective: Calculate the product of all even numbers from 1 to N.
Task: Input a number N and calculate the product of all even numbers from 1 to N.
Logic: Use a do-while loop to multiply even numbers and store the result.
Task 100: Print the factorial of numbers from 1 to N using a do-while loop
Objective: Print the factorial of all numbers from 1 to N.
Task: Input a number N and print the factorial for each number from 1 to N.
Logic: Use a do-while loop to calculate the factorial for each number and print it.