Basic programming exercises and solutions in C

Let us see a list of important Basic programming exercises and solutions in C++.

  1. Cube of a number 
  2. Convert temperature in Celsius to Fahrenheit
  3. Area of Rectangle
  4. Concatenate two strings
  5. Program to find the length of a string in C, CPP, C Plus Plus with flowchart
  6. Swapping Program in C++ (C Plus Plus)
  7. Solve expression program in C++ (C Plus Plus)
  8. simple compound assignment program in C++ (C Plus Plus).
  9. Find time, distance and speed in C++(C Plus Plus)
  10. Show personal details program in C++(C plus Plus)
  11. Cube of a number Program in C, CPP, C Plus Plus (C++) with flowchart
  12. Program in C, C Plus Plus (CPP) to display the ASCII Values with flowchart
  13. Program to convert temperature in Celsius to Fahrenheit in c++ and C with flowchart
  14. Area of Rectangle Program in C,C++ (C Plus Plus , CPP) with flowchart
  15. Program to Concatenate two strings in C++ (CPP, C Plus Plus) and C Languages with flow chart
  16. Arithmetic operation program in C++ (C Plus Plus) – Addition- Subtraction- Multiplication -Division
  17. Find Quotient and Remainder in C++(C Plus Plus)
  18. Convert hours into minutes and seconds program in C++ (C Plus Plus).
  19. Write a C++ program that prompts the user to enter values for a b and c
  20. Write a C++ program to calculate the wind chill factor
  21. Write a program that inputs principal amount, rate of interest and total time. It calculates the compound interest and displays it.
  22. C++ Program Basic Salary of the employee with dearness allowance
  23. Write a program that inputs the x, y coordinates for two points and computes distance between two points
  24. Write a program that display the following output using single cout
  25. Write a C++ program that Accept 5 digits number from the user
  26. Write a program which accepts days as integer and display total number of years
  27. Write a program which accepts a character and display its next character.
  28. A car can travel 5.3 miles in 1 liter. Write a program that inputs petrol in liters
  29. shamil memory table

If else programming Exercise and solution

  1. Let us see a list of important If else programming exercises and solutions in C++.
  2. Program to calculate the bill in c++
  3. CPP program to check that the entered character is small, capital, or a special character
  4. Program in C++ to check that whether a number is even or odd with flowchart
  5. 0 is a positive or negative number
  6. Program to find the positive and negative number
  7. Enter Range of numbers and replaced them in C++
  8. Program to find greater number among three numbers in c++ and C with flowchart
  9. Armstrong Number Program in C++, C Plus Plus CPP with Flowchart
  10. ASCII code Program in C++ (C Plus Plus)
  11. Find the Maximum value program in C++ (C Plus Plus).
  12. C++  Program to find the maximum between three numbers by using the if-else statement. C++ Program for the maximum number
  13. C++  Program to take a value from the user as input the basic salary of an employee and calculate its Gross salary according to the following: Basic Salary <= 10000: HRA = 20%, DA = 80%………………………………..Basic Salary <= 20000 : HRA = 25%, DA = 90%………………………………Basic Salary > 20000 : HRA = 30%, DA = 95%.
  14. C++  Program to find the maximum between two numbers by using the if-else statement. Maximum Number Program
  15.  Using the if-else C++  Program to take a value from the user as input electricity unit charges and calculate total electricity bill according to the given condition: For the first 50 units Rs. 0.50/unit………….For the next 100 units Rs. 0.75/unit…..For the next 100 units Rs. 1.20/unit ……………For unit above 250 Rs. 1.50/unit………An additional surcharge of 20% is added to the bill…….Using if-else.
  16. Write a program that determines a student’s grade. The program will read three types of scores (quiz, mid-term, and final scores) and determine the grade based on the following rules:if the average score =90% =>grade=A…………………..-if the average score >= 70% and <90% => grade=B……………………-if the average score>=50% and <70% =>grade=C……………………..-if the average score<50% =>grade=F.
  17. C++  Program to check whether a number is divisible by 5 and 11 or not by using if-else. The number is divisible by 11 or 5 or not
  18. C++  Program to count the total number of notes in a given amount. Using if-else
  19. C++  Program to take a value from the user as input the angles of a triangle and check whether the triangle is valid or not by using the if-else statement. Triangle program
  20. C++  Program to take a value from the user as input all sides of a triangle and check whether the triangle is valid or not. Using if-else.
  21. C++  Program to check whether the triangle is an equilateral, isosceles or scalene triangle. Using the if-else statement.
  22. C++  Program to find all the roots of a quadratic equation. Using if-else.
  23. C++  Program to calculate profit or loss. Using if-else.
  24. C++  Program to check whether a year is a leap year or not by using an if-else statement. Leap year program
  25. C++  Program to check whether a character is an alphabet or not. Using if-else.
  26. C++  Program to take a value from the user as input any alphabet and check whether it is vowel or consonant. Using if-else.
  27. Using if-else C++  Program to take a value from the to take a value from the user as input  marks of five subjects Physics, Chemistry, Biology, Mathematics, and Computer. Calculate percentage and grade according to the following: Percentage >= 90% : Grade A, Percentage >= 80% : Grade B, Percentage >= 70% : Grade C, Percentage >= 60% : Grade D, Percentage >= 40% : Grade E, Percentage < 40% : Grade F, Write this program with the help of  if-else statement. Grade and Percentage Program
  28. C++  Program to take a value from the user as input any character and check whether it is the alphabet, digit or special character. Using if-else.
  29. C++  Program to check whether a character is an uppercase or lowercase alphabet. Using if-else.
  30. C++  Program to take value from the user as an input weekday number and print weekday by using if-else statement. Weekday program
  31. C++  Program to take a value from the user as input the month number and print number of days in that month. Using if-else.\
  32. C++ Program to check whether a number is a prime or composite number.
  33. Program to take the hours and minutes as input by the user and the show that whether it is AM or PM using if-else statement
  34. Write a program to swap the values of two number if values of both variables are not the same using if-else statement
  35. Program to update even number into its upper nearest odd number. C++ Program to update even to odd
  36. Write a C program to calculate profit or loss by using if-else. Profit Loss Program
  37. Write a C++ Program to convert centimeter into meter and kilometer using the if-else statement. Program of centimeter into meter and kilometer 
  38. Write a C++ program to input all sides of a triangle and check whether the triangle is valid or not. Using the switch statement. Triangle Program
  39. C PROGRAM TO INPUT THE BASIC SALARY OF AN EMPLOYEE AND CALCULATE ITS GROSS SALARY BY USING THE IF-ELSE STATEMENT –  Salary Program
  40. Write a C++ program in which a user enters a number, and the program will find the Even and odd number. Your program should only accept integers of length 2 or higher and should ask the user to re-enter a value if the value containing total numbers of integers less than 2. The program with goto statement. Even odd program with goto statement.
  41. C++ program to calculate area of the circle if the radius is greater than 0 using goto statement.
  42. Write a C++ program to find the roots of a quadratic equation ax2 + bx + c = 0
  43. Basic Tutorial of conditional statements

Switch Exercise and solution

  1. Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
    Percentage >= 90% : Grade A
    Percentage >= 80% : Grade B
    Percentage >= 70% : Grade C
    Percentage >= 60% : Grade D
    Percentage >= 40% : Grade E
    Percentage < 40% : Grade F
  2. C++  Program to find the maximum between two numbers. Using the switch statement. Download Program to find maximum
  3.  C++  Program to find the maximum between three numbers. Using the switch statement.
  4.  C++  Program to check whether a number is divisible by 5 and 11 or not. Using the switch statement.
  5.  C++  Program to check whether a year is a leap year or not. Using switch statement
  6.  C++  Program to check whether a character is an alphabet or not. Using the switch statement. Click Here
  7.  C++  Program to take the value from the user as input any alphabet and check whether it is vowel or consonant. Using the switch statement. C++Program to check Vowel
  8.  C++  Program to take the value from the user as input any character and check whether it is the alphabet, digit or special character. Using the switch statement.  C++  Program Details
  9.  C++  Program to check whether a character is an uppercase or lowercase alphabet. Using the switch statement. Click Here
  10.  C++  Program to take the value from the user as an input week number and print weekday by using the switch statement. Weekday Program
  11.  C++  Program to take the value from the user as input the month number and print number of days in that month. Using switch statement – Click Here
  12.  C++  Program to count the total number of notes in a given amount. Using the switch statement. Click Here
  13.  C++  Program to take the value from the user as input all sides of a triangle and check whether the triangle is valid or not. Using switch statement – Click Here
  14.  C++  Program to check whether the triangle is an equilateral, isosceles or scalene triangle. Using switch statement
  15.  C++  Program to find all the roots of a quadratic equation. Using switch statement
  16.  C++  Program to calculate profit or loss. Using switch statement. Program to calculate profit or loss
  17. Using switch statement  C++  Program to take the value from the user as input marks of five subjects Physics, Chemistry, Biology, Mathematics, and Computer. Calculate percentage and grade according to the following: Percentage >= 90% : Grade A, Percentage >= 80% : Grade B, Percentage >= 70% : Grade C, Percentage >= 60% : Grade D, Percentage >= 40% : Grade E, Percentage < 40% : Grade F, Using switch statement.
  18.  C++  Program to take the value from the user as input the basic salary of an employee and calculate its Gross salary according to the following: Basic Salary <= 10000: HRA = 20%, DA = 80%………………………………..Basic Salary <= 20000 : HRA = 25%, DA = 90%………………………………Basic Salary > 20000 : HRA = 30%, DA = 95%.
  19. C++  Program to take the value from the user as input electricity unit charges and calculate total electricity bill according to the given condition: For the first 50 units Rs. 0.50/unit………….For the next 100 units Rs. 0.75/unit…..For the next 100 units Rs. 1.20/unit ……………For unit above 250 Rs. 1.50/unit………An additional surcharge of 20% is added to the bill…….Using the switch statement. C++Program to find the bill.
  20. Write a program that determines a student’s grade. The program will read three types of scores (quiz, mid-term, and final scores) and determine the grade based on the following rules:if the average score =90% =>grade=A…………………..-if the average score >= 70% and <90% => grade=B……………………-if the average score>=50% and <70% =>grade=C……………………..-if the average score<50% =>grade=F
  21. Program to take the hours and minutes as input by the user and the show that whether it is AM or PM by using the switch statement. Click Here
  22. Program to convert a positive number into negative number and negative number into a positive number using switch  statement Click Here
  23. Write a program to swap the values of two numbers if the values of both variables are not the same using a switch statement. C++ Code
  24. Program to Convert even number into its upper nearest odd number Switch Statement. Even and odd conversion program

Loop programming exercises and solutions

For loop

For loop is a methodology to use a piece of code again and again until the given condition remains true. Loop will terminate when the given condition will false.

  1. For loop have three parts. Loop initialization, Condition, and increment or decrement of a loop.
  2. Program to find the length of a number in C++ (CPP). Solution
  3. Program to find the square root of a number in C++. Solution
  4. Factorial Program in C, C++ (C Plus Plus, CPP) with flow chart. Solution
  5. Fibonacci Series Program in C++ and C with flowchart. Solution
  6. Palindrome Program in C, C++, C Plus Plus (CPP) with flow chart. Solution
  7. Program to the Print sum of the number of Series in C Plus Plus (CPP, C++) and C with Flowchart. Solution
  8. C++ and C Program to Find the Number of Vowels, Digits, Consonants and White Spaces in a String with flowchart. Solution
  9. Program in C++, C to display the reverse of a number with a flowchart. Solution
  10. Write a program that lets the user enter the total rainfall for each of 12 months
  11. Write a C++ program to print a triangle of prime numbers up to given number of lines of the triangle
  12. Write a C++ program to print all numbers between a and b (a and b inclusive) using for loops

while loop

  1. The while loop is a methodology to use a piece of code again and again until the given condition remains true. Loop will terminate when the given condition will false.
  2. Just lie for loop, the while loop has three parts. 1. Loop initialization, 2. Condition, and 3. increment or decrement of a loop.
  3. Program of the sum of all digits of a number in C, C Plus Plus (CPP, C++) with flow chart. the solution
  4. converts a number into binary in C++and C with a flowchart. Solution
  5. Program in C Plus Plus and C with an explanation to find the Greatest Common Division (GCD). Solution with flowchart. Solution
  6. C++ Program to convert Octal to decimal number using while loop. Solution
  7. Write a program using integers usernum and x as input, and output usernum divided by x four times.
  8. Write a C++ program to add two numbers without using the addition operator
  9. Write a C++ program that simulates the rolling of two dice

Do while loop

  1. In Do, while loop, first one time we execute the do part of the loop, and then we check the condition. It means that if the condition is false then still do part execute one time.
  2. C++ Program to Display English Alphabets from  A-Z. Solution
  3. <spanhelvetica’,’sans-serif’;”>Write a program in C++ to display the multiplication table vertically from 1 to n. Solution</spanhelvetica’,’sans-serif’;”>
  4. C++ Program to Find the Sum of Digits of a Number – C++ Program. Solution
  5. Program in C++ to display the n terms of even natural number and their sum. Solution
  6. C++ program to find the sum of all integer between 100 and 200 which are divisible by 9. Solution
  7. Write a program in C++ to print Floyd’s Triangle. Solution
  8. C++ program to print pyramid pattern of numbers.  Solution
  9. C++ Program to display the n terms of odd natural number and their sum. Solution
  10. Convert a binary number to octal in C++. Solution
  11. c++ program to check whether a given number is a perfect number or not. Solution
  12. C++ program to find HCF (Highest Common Factor) of two numbers. Solution
  13. Program in C++ to convert a decimal number into binary without using an array. Solution
  14. Program C++ to convert an octal number into binary. Solution
  15. Write a c program to find out the sum of an A.P. series. Solution
  16. Program in C++, C to display the reverse of a number with flowchart. Solution
  17. Write the Octal to Decimal number program in C++. Solution
  18. C++ Program right angle triangle with a number that will repeat a number in a row. Solution
  19. C++ program to print rhombus or parallelogram star pattern. Solution
  20. Program in C++ to make such a pattern like a pyramid with a number that will repeat the number in the same row. Solution
  21. Write a program in C++ to Check Whether a Number can be Express as a Sum of Two Prime Numbers. Solution
  22. C++ program to print mirrored right triangle star pattern. Solution
  23. Decimal to octal number conversion program in C++. Solution
  24. C++ program to print a hollow square or rectangle star pattern. Solution
  25. C++ Program Sum of odd Natural Number. Solution
  26. The sum of the first 10 natural numbers program in C++. Solution

Prefix and postfix

  1. Prefix and postfix increment and decrement in C++. Solution

Strings exercises and solutions

  1. Remove Whitespaces from the program

Arrays exercises and solutions

  1. Two’s complement of a binary number in C++

Pointers exercises and solutions

  1. Write a program in C++ to add two numbers using pointers

Star patterns exercises and solutions

  1. Program to print the stars in a sequence in C Plus Plus(C++, CPP) and C with flowchart
  2. Program to print the numbers in a specific pattern in C++ CPP and C with flowchart
  3. Pattern printing in  C++
  4. Program to print stars (steric) in a pattern in C++ (C plus plus)

Add a Comment