Codeforwin

Array and Matrix programming exercises and solutions in C

Array is a linear data structure that hold finite sequential collection of homogeneous data. We can store a collection of values in an array.

Array uses an integer value index to access a specific element. Index starts from 0 and goes till N-1 (where N is the size of array).

Array representation in memory

Arrays are divided in two categories.

  • One-dimensional array
  • Multi-dimensional array

In this exercise we will focus on one-dimensional and multi-dimensional array. We will learn to implement and use arrays in programming.

Always feel free to drop your queries and suggestions down in the comments section . I always love to hear from Codeforwin lovers.

Required knowledge

Basic C programming , Loop , Recursion , Arrays , Multi-dimensional array

List of array and matrix programming exercises

  • Write a C program to read and print elements of array . – using recursion .
  • Write a C program to print all negative elements in an array .
  • Write a C program to find sum of all array elements . – using recursion .
  • Write a C program to find maximum and minimum element in an array . – using recursion .
  • Write a C program to find second largest element in an array .
  • Write a C program to count total number of even and odd elements in an array .
  • Write a C program to count total number of negative elements in an array .
  • Write a C program to copy all elements from an array to another array .
  • Write a C program to insert an element in an array .
  • Write a C program to delete an element from an array at specified position .
  • Write a C program to count frequency of each element in an array .
  • Write a C program to print all unique elements in the array .
  • Write a C program to count total number of duplicate elements in an array .
  • Write a C program to delete all duplicate elements from an array .
  • Write a C program to merge two array to third array .
  • Write a C program to find reverse of an array .
  • Write a C program to put even and odd elements of array in two separate array .
  • Write a C program to search an element in an array .
  • Write a C program to sort array elements in ascending or descending order .
  • Write a C program to sort even and odd elements of array separately .
  • Write a C program to left rotate an array .
  • Write a C program to right rotate an array .

List of matrix programming exercises

  • Write a C program to add two matrices .
  • Write a C program to subtract two matrices .
  • Write a C program to perform Scalar matrix multiplication .
  • Write a C program to multiply two matrices .
  • Write a C program to check whether two matrices are equal or not .
  • Write a C program to find sum of main diagonal elements of a matrix .
  • Write a C program to find sum of minor diagonal elements of a matrix .
  • Write a C program to find sum of each row and column of a matrix .
  • Write a C program to interchange diagonals of a matrix .
  • Write a C program to find upper triangular matrix .
  • Write a C program to find lower triangular matrix .
  • Write a C program to find sum of upper triangular matrix .
  • Write a C program to find sum of lower triangular matrix .
  • Write a C program to find transpose of a matrix .
  • Write a C program to find determinant of a matrix .
  • Write a C program to check Identity matrix .
  • Write a C program to check Sparse matrix .
  • Write a C program to check Symmetric matrix .
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors
  • C File Handling
  • C Cheatsheet
  • C Interview Questions

C Exercises - Practice Questions with Solutions for C Programming

The best way to learn C programming language is by hands-on practice. This C Exercise page contains the top 30 C exercise questions with solutions that are designed for both beginners and advanced programmers. It covers all major concepts like arrays, pointers, for-loop, and many more.

C-Exercises

So, Keep it Up! Solve topic-wise C exercise questions to strengthen your weak topics.

Also, Once you've covered basic C exercises, the GeeksforGeeks Practice Platform is a great place to take on more advanced C coding problems and improve your understanding.

C Programming Exercises

The following are the top 30 programming exercises with solutions to help you practice online and improve your coding efficiency in the C language. You can solve these questions online in GeeksforGeeks IDE.

Q1: Write a Program to Print "Hello World!" on the Console.

In this problem, you have to write a simple program that prints "Hello World!" on the console screen.

For Example,

Click here to view the solution.

Q2: write a program to find the sum of two numbers entered by the user..

In this problem, you have to write a program that adds two numbers and prints their sum on the console screen.

Q3: Write a Program to find the size of int, float, double, and char.

In this problem, you have to write a program to print the size of the variable.

Q4: Write a Program to Swap the values of two variables.

In this problem, you have to write a program that swaps the values of two variables that are entered by the user.

Swap-two-Numbers

Q5: Write a Program to calculate Compound Interest.

In this problem, you have to write a program that takes principal, time, and rate as user input and calculates the compound interest.

Q6: Write a Program to check if the given number is Even or Odd.

In this problem, you have to write a program to check whether the given number is even or odd.

Q7: Write a Program to find the largest number among three numbers.

In this problem, you have to write a program to take three numbers from the user as input and print the largest number among them.

Q8: Write a Program to make a simple calculator.

In this problem, you have to write a program to make a simple calculator that accepts two operands and an operator to perform the calculation and prints the result.

Q9: Write a Program to find the factorial of a given number.

In this problem, you have to write a program to calculate the factorial (product of all the natural numbers less than or equal to the given number n) of a number entered by the user.

Q10: Write a Program to Convert Binary to Decimal.

In this problem, you have to write a program to convert the given binary number entered by the user into an equivalent decimal number.

Q11: Write a Program to print the Fibonacci series using recursion.

In this problem, you have to write a program to print the Fibonacci series(the sequence where each number is the sum of the previous two numbers of the sequence) till the number entered by the user using recursion.

FIBONACCI-SERIES

Q12: Write a Program to Calculate the Sum of Natural Numbers using recursion.

In this problem, you have to write a program to calculate the sum of natural numbers up to a given number n.

Q13: Write a Program to find the maximum and minimum of an Array.

In this problem, you have to write a program to find the maximum and the minimum element of the array of size N given by the user.

Q14: Write a Program to Reverse an Array.

In this problem, you have to write a program to reverse an array of size n entered by the user. Reversing an array means changing the order of elements so that the first element becomes the last element and the second element becomes the second last element and so on.

reverseArray

Q15: Write a Program to rotate the array to the left.

In this problem, you have to write a program that takes an array arr[] of size N from the user and rotates the array to the left (counter-clockwise direction) by D steps, where D is a positive integer. 

Q16: Write a Program to remove duplicates from the Sorted array.

In this problem, you have to write a program that takes a sorted array arr[] of size N from the user and removes the duplicate elements from the array.

Q17: Write a Program to search elements in an array (using Binary Search).

In this problem, you have to write a program that takes an array arr[] of size N and a target value to be searched by the user. Search the target value using binary search if the target value is found print its index else print 'element is not present in array '.

Q18: Write a Program to reverse a linked list.

In this problem, you have to write a program that takes a pointer to the head node of a linked list, you have to reverse the linked list and print the reversed linked list.

Q18: Write a Program to create a dynamic array in C.

In this problem, you have to write a program to create an array of size n dynamically then take n elements of an array one by one by the user. Print the array elements.

Q19: Write a Program to find the Transpose of a Matrix.

In this problem, you have to write a program to find the transpose of a matrix for a given matrix A with dimensions m x n and print the transposed matrix. The transpose of a matrix is formed by interchanging its rows with columns.

Q20: Write a Program to concatenate two strings.

In this problem, you have to write a program to read two strings str1 and str2 entered by the user and concatenate these two strings. Print the concatenated string.

Q21: Write a Program to check if the given string is a palindrome string or not.

In this problem, you have to write a program to read a string str entered by the user and check whether the string is palindrome or not. If the str is palindrome print 'str is a palindrome' else print 'str is not a palindrome'. A string is said to be palindrome if the reverse of the string is the same as the string.

Q22: Write a program to print the first letter of each word.

In this problem, you have to write a simple program to read a string str entered by the user and print the first letter of each word in a string.

Q23: Write a program to reverse a string using recursion

In this problem, you have to write a program to read a string str entered by the user, and reverse that string means changing the order of characters in the string so that the last character becomes the first character of the string using recursion. 

Reverse-a-String

Q24: Write a program to Print Half half-pyramid pattern.

In this problem, you have to write a simple program to read the number of rows (n) entered by the user and print the half-pyramid pattern of numbers. Half pyramid pattern looks like a right-angle triangle of numbers having a hypotenuse on the right side.

Q25: Write a program to print Pascal’s triangle pattern.

In this problem, you have to write a simple program to read the number of rows (n) entered by the user and print Pascal’s triangle pattern. Pascal’s Triangle is a pattern in which the first row has a single number 1 all rows begin and end with the number 1. The numbers in between are obtained by adding the two numbers directly above them in the previous row.

pascal-triangle

Q26: Write a program to sort an array using Insertion Sort.

In this problem, you have to write a program that takes an array arr[] of size N from the user and sorts the array elements in ascending or descending order using insertion sort.

Q27: Write a program to sort an array using Quick Sort.

In this problem, you have to write a program that takes an array arr[] of size N from the user and sorts the array elements in ascending order using quick sort.

Q28: Write a program to sort an array of strings.

In this problem, you have to write a program that reads an array of strings in which all characters are of the same case entered by the user and sort them alphabetically. 

Q29: Write a program to copy the contents of one file to another file.

In this problem, you have to write a program that takes user input to enter the filenames for reading and writing. Read the contents of one file and copy the content to another file. If the file specified for reading does not exist or cannot be opened, display an error message "Cannot open file: file_name" and terminate the program else print "Content copied to file_name"

Q30: Write a program to store information on students using structure.

In this problem, you have to write a program that stores information about students using structure. The program should create various structures, each representing a student's record. Initialize the records with sample data having data members' Names, Roll Numbers, Ages, and Total Marks. Print the information for each student.

We hope after completing these C exercises you have gained a better understanding of C concepts. Learning C language is made easier with this exercise sheet as it helps you practice all major C concepts. Solving these C exercise questions will take you a step closer to becoming a C programmer.

Frequently Asked Questions (FAQs)

Q1. what are some common mistakes to avoid while doing c programming exercises.

Some of the most common mistakes made by beginners doing C programming exercises can include missing semicolons, bad logic loops, uninitialized pointers, and forgotten memory frees etc.

Q2. What are the best practices for beginners starting with C programming exercises?

Best practices for beginners starting with C programming exercises: Start with easy codes Practice consistently Be creative Think before you code Learn from mistakes Repeat!

Q3. How do I debug common errors in C programming exercises?

You can use the following methods to debug a code in C programming exercises Read the error message carefully Read code line by line Try isolating the error code Look for Missing elements, loops, pointers, etc Check error online

Similar Reads

Improve your coding skills with practice.

 alt=

What kind of Experience do you want to share?

IMAGES

  1. Arrays in C (Solved Problem 1)

    array problem solving questions in c

  2. Array in C#: Solving Simple Problem

    array problem solving questions in c

  3. Arrays in C (Solved Problem 2)

    array problem solving questions in c

  4. C-Array Problem Solving Part-2 (From RUET LabSheet-5)

    array problem solving questions in c

  5. Array_08

    array problem solving questions in c

  6. 10 C Problem Solving with Arrays

    array problem solving questions in c

VIDEO

  1. MCQ's on Array in C

  2. Must do problems on Arrays

  3. C++ Array Problem Solving With git Push

  4. LeetCode Merge Sorted Array

  5. C language Final Past Paper Question 02

  6. Split the Array || GFG Problem of the day || 21 oct 2024 || Takla Coder's Walkthrough