Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Programming examples

  1. Hello, World!: Write a program that prints the message “Hello, World!”.
  2. Sum of Two Numbers: Write a program that asks the user to enter two numbers, and then prints the sum of those two numbers.
  3. Addition: Write a program that assigns three numbers to variables num1, num2 and num3, and then calculates their sum and stores it in a variable result. Finally, print the value of result.
  4. Even or Odd: Write a program that asks the user to enter a number and then determines whether the number is even or odd.
  5. String Concatenation: Write a program that concatenates two strings str1 and str2 and stores the result in a variable result.
  6. Increment and Decrement: Write a program that increments and decrements the value of a variable num.
  7. User Input: Write a program that asks the user to enter their name, stores it in a variable name, and then prints a greeting using the name.

Programming problems to practice data types:

  1. Write a program that swaps the values of two variables using a temporary variable.
  2. Write a program that swaps the values of two variables without using a temporary variable.
  3. Write a program that takes a number as input and converts it into integer, float, and string.
  4. Write a program that takes a string as input and find the length of the string.
  5. Write a program that takes a string as input and convert it to uppercase or lowercase.

Programming problems to practice loops:

  1. Write a program that prints the numbers from 1 to 10.
  2. Write a program that prints the even numbers from 1 to 20.
  3. Write a program that prints the sum of all numbers from 1 to 100.
  4. Write a program that calculates the factorial of a given number.
  5. Write a program that prints the Fibonacci sequence up to a given number.
  6. Write a program that checks if a given number is prime.
  7. Write a program that prints the multiplication table of a number.
  8. Write a program that finds the largest element in an array.
  9. Write a program that prints the reverse of a given string.
  10. Write a program that calculates the sum of all elements in a list.

Programming problems to practice conditions:

  1. Write a program that takes an integer N as input and determines whether it is even or odd.
  2. Write a program that takes an integer N as input and determines whether it is positive, negative, or zero.
  3. Write a program that takes three numbers as input and determines the largest among them using conditional statements.
  4. Write a program that takes a year as input and determines whether it is a leap year or not.
  5. Write a program that takes a student’s score as input and calculates the corresponding grade based on the following conditions:
    • 90 or above: A
    • 80 to 89: B
    • 70 to 79: C
    • 60 to 69: D
    • Below 60: F
  6. Write a program that takes a character as input and determines whether it is a vowel or consonant.
  7. Write a program that takes three numbers as input and determines whether their product is positive or negative.
  8. Write a program that takes an integer N as input and determines whether it is divisible by both 5 and 7.
  9. Write a program that takes three angles of a triangle as input and determines whether it is an equilateral, isosceles, or scalene triangle.
  10. Write a program that takes an integer N as input and determines whether it falls within a specific range, such as 1 to 100.

Programming problems to practice functions:

  1. Write a function that calculates the factorial of a given number N and returns the result.
  2. Write a function that takes a string as input and determines whether it is a palindrome or not.
  3. Write a function that takes two integers as input and calculates their greatest common divisor.
  4. Write functions to calculate the area of different geometric shapes such as squares, rectangles, circles, and triangles.
  5. Write a function that takes two strings as input and determines whether they are anagrams (contain the same characters in a different order) or not.
  6. Write functions to convert temperatures between Fahrenheit and Celsius.

Programming problems to practice array:

  1. Write a program that takes an array of integers as input and calculates the sum of all the elements in the array.
  2. Write a program that takes an array of integers as input and calculates the average of all the elements in the array.
  3. Write a program that takes an array of integers as input and determines the smallest element in the array.
  4. Write a program that takes an array of integers as input and returns a new array with the elements in reverse order.
  5. Write a program that takes an array of integers as input and sorts the elements in ascending or descending order.
  6. Write a program that takes an array of integers and a target number as input and determines whether the target number is present in the array.
  7. Write a program that takes an array of integers and a rotation count as input. Rotate the elements of the array to the right by the given rotation count.
  8. Write a program that takes two arrays of integers as input and returns a new array containing the common elements between the two arrays.
  9. Write a program that takes an array of integers and a value to remove as input. Remove all occurrences of the value from the array and return the modified array.

Word Problems:

  1. Sandip wants to buy a new smartphone that costs Rs 5000. She has saved Rs 2500 so far. How much more money does Sandip need to save?
  2. Dheeraj is planning a road trip. The total distance he wants to cover is 800 kilometers. If he has already driven 450 kilometers, how many more kilometers does he need to travel?
  3. Ayushman wants to distribute 120 candies equally among his 5 friends. How many candies will each friend receive, and how many candies will be left with Ayushman?
  4. PIn a store, a book costs Rs 250. If Kunal wants to buy 4 books, what will be the total cost?
  5. A recipe requires 2 cups of milk, 1 cup of sugar, and 3 mangoes. If Adarsh wants to double the recipe, how much milk, sugar, and mangoes will he need?