Tag Archives: Exercises

Number pattern programs in C

Number pattern is a series of numbers arranged in specific order. These patterns are patterns created by numbers and are similar to star patterns. They are best suited to enhance your logical thinking abilities and to practice flow control statements.

I have assembled a list of number patterns to practice for both novice as well as intermediate programmers. Practice more and more of it, to enhance your logical thinking.

Always feel free to drop down your queries and suggestions below in the comments section. I always love to hear from hugs and bugs from you.

Required knowledge

Basic C programming, Operators, If else, Nested If else, For loop, Nested loop

List of Number pattern programming exercises

Square number patterns

Triangle Easy Number Patterns


Triangle 0,1 Easy Number Patterns


Triangle Hard Number Patterns


Diamond Number Patterns


Tricky Number Patterns


Happy coding 😉

Functions programming exercises and solutions in C

A function is a collection of statements grouped together to do some specific task. In series of learning C programming, we already used many functions unknowingly. Functions such as - printf(), scanf(), sqrt(), pow() or the most important the main() function. Every C program has at least one function i.e. the main() function.

Function provides modularity to our program. Dividing a program in different modules makes it easy to maintain, debug and understand the code.

Continue reading Functions programming exercises and solutions in C

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

Star patterns in C programming

Star patterns are a series of * or any other character used to create some pattern or any geometrical shape such as - square, triangle(Pyramid), rhombus, heart etc. These patterns are often prescribed by many programming books and are best for practicing flow control statement.

Many programmers around world extremely recommended pattern problems, to enhance logical thinking capabilities. As a novice programmer you must practice these patterns to get a good hands on logical thinking and program flow control.

In this exercise I have compiled a list of Star patterns to practice for beginners and intermediate programmers. I have tried my best to explain the logic of each pattern individually.

If you got stuck with some pattern or have some query or suggestion, always feel free to write it down below in the comments section. I always love to hear from you all.

Required knowledge

Basic C programming, Operators, If else, For loop, Nested loop

List of star pattern programming exercises

Loop programming exercises and solutions in C

In programming, there exists situations when you need to repeat single or a group of statements till some condition is met. Such as - read all files of a directory, send mail to all employees one after another etc. These task in C programming is handled by looping statements.

Looping statement defines a set of repetitive statements. These statements are repeated with same or different parameters for a number of times. Looping statement is also known as iterative or repetitive statement.

C supports three looping statements.

In this exercise we will practice lots of looping problems to get a strong grip on loop. This is most recommended C programming exercise for beginners.

Always feel free to drop your queries, suggestions, hugs or bugs down below in the comments section. I always look forward to hear from you.

Required knowledge

Basic C programming, Relational operators, Logical operators, If else, For loop

List of loop programming exercises

  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

Conditional operator is a ternary operator used to evaluate expression based on some condition. Conditional operator is a replacement of small if...else statements. It takes three operand conditional-expression, true-expression and false-expression It is also known as ternary operator, inline if, ternary if etc.

Continue reading Conditional operator programming exercises and solutions in C

Switch case programming exercises and solutions in C

switch...case is a branching statement used to perform action based on available choices, instead of making decisions based on conditions. Using switch...case you can write more clean and optimal code than if...else statement.

switch...case only works with integer, character and enumeration constants.

In this exercises we will focus on the use of switch...case statement. We will learn where to implement switch...case statement other than if...else statement.

Continue reading Switch case programming exercises and solutions in C

If else programming exercises and solutions in C

if...else is a branching statement. It is used to take an action based on some condition. For example - if user inputs valid account number and pin, then allow money withdrawal.

If statement works like "If condition is met, then execute the task". It is used to compare things and take some action based on the comparison. Relational and logical operators supports this comparison.

Continue reading If else programming exercises and solutions in C