Tag Archives: Exercises

Number pattern programs in C

Number patterns are logical programs that basically are used to enhance your logical thinking abilities. These patterns are patterns created by numbers and are similar to star patterns. Enhance your logical thinking abilities by coding these patterns. Here is a list of basic, advanced, tricky and popular number patterns with logic and explanation. Learn how to print all these number pattern programs in C. Practice more and more of it to enhance your logical thinking.


Functions programming exercises and solutions in C

Functions in programming is a block of statements grouped together to perform some specific task. Functions provides modularity to our program which are easy to maintain, debug and understand. Functions in C programming can be classified in two category i.e. predefined or library functions and user defined functions. Below is a list of programming exercises based on functions and recursion to practice for beginners to advance their programming capabilities with functions. Here in this programming exercise we will mainly focus on user defined functions and recursion.

  1. Write a C program to find cube of any number using function.
  2. Write a C program to find diameter, circumference and area of circle using functions.
  3. Write a C program to find maximum and minimum between two numbers using functions.
  4. Write a C program to check whether a number is even or odd using functions.
  5. Write a C program to check whether a number is prime, Armstrong or perfect number using functions.
     
  6. Write a C program to find all prime numbers between given interval using functions.
  7. Write a C program to print all strong numbers between given interval using functions.
  8. Write a C program to print all Armstrong numbers between given interval using functions.
  9. Write a C program to print all perfect numbers between given interval using functions.
     
  10. Write a C program to find power of any number using recursion.
  11. Write a C program to print all natural numbers between 1 to n using recursion.
  12. Write a C program to print all even or odd numbers in given range using recursion.
  13. Write a C program to find sum of all natural numbers between 1 to n using recursion.
  14. Write a C program to find sum of all even or odd numbers in given range using recursion.
  15. Write a C program to find reverse of any number using recursion.
  16. Write a C program to check whether a number is palindrome or not using recursion.
  17. Write a C program to find sum of digits of a given number using recursion.
  18. Write a C program to find factorial of any number using recursion.
  19. Write a C program to generate nth Fibonacci term using recursion.
  20. Write a C program to find GCD (HCF) of two numbers using recursion.
  21. Write a C program to find LCM of two numbers using recursion.
     
  22. Write a C program to display all array elements using recursion.
  23. Write a C program to find sum of elements of array using recursion.
  24. Write a C program to find maximum and minimum elements in array using recursion.

Happy coding 😉

Bitwise operator programming exercises and solutions in C

Data in the memory (RAM) is organized as a sequence of bytes. Each byte is a group of eight consecutive bits. Bitwise operators are useful when we need to perform actions on bits of the data.

C supports six bitwise operators.

  1. Bitwise AND operator &
  2. Bitwise OR operator |
  3. Bitwise XOR operator ^
  4. Bitwise complement operator ~
  5. Bitwise left shift operator <<
  6. Bitwise right shift operator >>

This exercises focuses on mastering bitwise operators. After this exercise you will surely gain some confidence using bitwise operators.

Continue reading Bitwise operator programming exercises and solutions in C

String programming exercises and solutions in C

Strings are basically array of characters that represent some textual data in a program. Here are basic string programs with detailed explanation that will help to enhance your string programming skills. These exercises can be practiced by anyone a beginner or an intermediate programmers.

  1. Write a C program to find length of a string.
  2. Write a C program to copy one string to another string.
  3. Write a C program to concatenate two strings.
  4. Write a C program to compare two strings.
    Continue reading String programming exercises and solutions in C

Array and Matrix programming exercises and solutions in C

Array is a linear collection of similar data types elements. Array in C programming are used to store more than one value at a time in a variable which can be easily accessed by their index. Array can be categorized in two categories:

  1. Single dimension array
  2. Multi dimension array

Here is a list of simple programs on array and matrix to practice for beginners:

  1. Write a C program to read and print elements of array. - using recursion.
  2. Write a C program to print all negative elements in an array.
  3. Write a C program to find sum of all array elements. - using recursion.
  4. Write a C program to find maximum and minimum element in an array. - using recursion.
  5. Write a C program to find second largest element in an array.
  6. Write a C program to count total number of even and odd elements in an array.
  7. Write a C program to count total number of negative elements in an array.
  8. Write a C program to copy all elements from an array to another array.
  9. Write a C program to insert an element in an array.
  10. Continue reading Array and Matrix programming exercises and solutions in C

Loop programming exercises and solutions in C

Loops in programming are used to perform repetitive tasks. If there is a statement which is to be repeated multiples times we use loop. There are generally three types of loops.

Here is a set of programming exercises based on loops to practice.

  1. Write a C program to print all natural numbers from 1 to n. - using while loop
  2. Write a C program to print all natural numbers in reverse (from n to 1). - using while loop
  3. Write a C program to print all alphabets from a to z. - using while loop
  4. Write a C program to print all even numbers between 1 to 100. - using while loop
  5. Write a C program to print all odd number between 1 to 100.
  6. Write a C program to find sum of all natural numbers between 1 to n.
  7. Write a C program to find sum of all even numbers between 1 to n.
  8. Continue reading Loop programming exercises and solutions in C

Conditional operator programming exercises and solutions in C

Ternary operator is a shorthand operator for if else and can be used to replace short if else statements in single line. Ternary operator is also known as conditional operator, inline if, ternary if.

Here is a list of programming problems based on conditional operator to practice for beginners.

  1. Write a C program to find maximum between two numbers using conditional/ternary operator.
  2. Write a C program to find maximum between three numbers using conditional/ternary operator.
  3. Write a C program to check whether a number is even or odd using conditional/ternary operator.
  4. Write a C program to check whether year is leap year or not using conditional/ternary operator.
  5. Write a C program to check whether character is an alphabet or not using conditional/ternary operator.

Continue reading Conditional operator programming exercises and solutions in C

Switch case programming exercises and solutions in C

Switch case is a conditional control statement that allows us to make decisions from number of available choices. It uses an integer value or an enumeration type value for making decisions.

Here is a set of basic programming problems based on switch case to practice.

  1. Write a C program to print day of week name using switch case.
  2. Write a C program print total number of days in a month using switch case.
  3. Write a C program to check whether an alphabet is vowel or consonant using switch case.
  4. Write a C program to find maximum between two numbers using switch case.
  5. Write a C program to check whether a number is even or odd using switch case.
  6. Write a C program to find roots of a quadratic equation using switch case.
  7. Write a C program to create Simple Calculator using switch case.

Continue reading Switch case programming exercises and solutions in C

If else programming exercises and solutions in C

If else statements are the conditional control statements. They are used to perform any condition based operation. If else statements works on a boolean value. If the boolean value is true then the statements under if are executed else they are skipped. In C any non-zero integer value is treated as true and zero is treated as false.
Basically there are four types of if-else:

Here is a set of basic programming problems based on if else to practice for beginners.

  1. Write a C program to find maximum between two numbers.
  2. Write a C program to find maximum between three numbers.
  3. Write a C program to check whether a number is negative, positive or zero.
  4. Write a C program to check whether a number is divisible by 5 and 11 or not.
  5. Write a C program to check whether a number is even or odd.
  6. Write a C program to check whether a year is leap year or not.
  7. Continue reading If else programming exercises and solutions in C

Basic programming exercises and solutions in C

C programming is a stepping stone for many programmers in the programming world. C is best to learn internals of programming and know how a computer program works internally.

Since it is close to low level programming. Programming in C can be a nightmare for beginners if not practiced properly. However, you can learn and practice at Codeforwin step by step.

In this programming exercise we will focus on basics of C programming. After completing this exercise you will learn basic structure and semantics of a C program and how to write mathematical programs in C.

Continue reading Basic programming exercises and solutions in C