Category Archives: C Programs

C Programs

C Program to Check Two Matrices are Equal or Not

C Program to Check Two Matrices are Equal or Not

In this tutorial, we will learn to create a C program that will check the Two Matrices are Equal or Not using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

Algorithm:-

Program to check the matrix equal or not:-

In this tutorial, we will check the matrix is equal or not with the help of the c programming. First, we will take the size and the elements of the matrix. Then we will check the matrix is equal or not using the for loop and the conditional statements. Then will print the output to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value for loop.
  • cl = it will hold the integer value for loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the two matrices from the user.

Checking the matrix is equal or not.

Printing the Matrix is equal or not.

C Program to check Matrix is a Symmetric Matrix

C Program to check Matrix is a Symmetric Matrix

In this tutorial, we will learn to create a C program that will check the Matrix is a Symmetric Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

Algorithm:-

Program to check the matrix:-

In this tutorial, we will check the matrix is symmetric or not with the help of the c programming. First, we will take the size and the elements of the matrix. Then we will check transpose the matrix using the code. Now we will compare the two matrices and if they are symmetric or not. Then will print the output to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value for loop.
  • cl = it will hold the integer value for loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Checking the matrix is symmetric or not a symmetric matrix.

Printing the Matrix is symmetric or not.

C Program to Find Sum of Opposite Diagonal Elements in a Matrix

C Program to Find Sum of Opposite Diagonal Elements in a Matrix

In this tutorial, we will learn to create a C program that will find the Sum of Opposite Diagonal Elements in a Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

Algorithm:-

With the help of this program, we can find the Sum of Opposite Diagonal Elements in a Matrix.

Program to find Sum of Opposite Diagonal Elements in a Matrix:-

In this tutorial, we will find the Sum of Opposite Diagonal Elements in a Matrix. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrix. Now we will find the sum of the diagonal elements in the matrix. At last, we will find the sum of the opposite diagonal elements of the matrix. Then we will print the result to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value for loop.
  • cl = it will hold the integer value for loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Adding the opposite diagonal elements of the matrix.

Printing the Sum of opposite diagonal elements of the Matrix.

C Program to Find Sum of Lower Triangle Matrix

C Program to Find Sum of Lower Triangle Matrix

In this tutorial, we will learn to create a C program that will find the Sum of Lower Triangle Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

Algorithm:-

With the help of this program, we can find the Sum of the Lower Triangle Matrix.

Program to find Sum of the Lower Triangle Matrix:-

In this tutorial, we will create a multidimensional array with the help of C programming. First, we will take the size of the array from the user, and then we will take the input elements. Now we will create a Lower triangle in the matrix by adding a zero in rows. At last, we will find the sum of the Lower right triangle of the matrix. Then we will print the sum

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value.
  • clm = it will hold the integer value.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Creating the Lower right triangle from the matrix and adding the elements.

Printing the Sum of Lower Triangle Matrix.

C Program to Find Sum of Upper Triangle Matrix

C Program to find Upper Triangle Matrix

In this tutorial, we will learn to create a C program that will find the Sum of Upper Triangle Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

What is a matrix?

A matrix is a multidimensional phenomenon and is created with the help of a 2d array having multiple rows and columns.

Algorithm:-

With the help of this program, we can find the Sum of the Upper Triangle Matrix.

Program to find Sum of the Upper Triangle Matrix:-

In this tutorial, we will create a multidimensional array with the help of C programming. First, we will take the size of the array from the user, and then we will take the input elements. Now we will create an upper triangle in the matrix by adding a zero in rows. At last, we will find the sum of the upper right triangle of the matrix. Then we will print the sum

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value.
  • clm = it will hold the integer value.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Creating the upper right triangle from the matrix and adding the elements.

Printing the Sum of Upper Triangle Matrix.

C Program to Find Transpose Of a Matrix

C Program to Find Transpose Of a Matrix

In this tutorial, we will learn to create a C program that will find Transpose Of a Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

What is a matrix?

A matrix is a multidimensional phenomenon and is created with the help of a 2d array having multiple rows and columns.

Algorithm:-

With the help of this program, we can find Transpose Of a Matrix.

Program to find Transpose Of a Matrix:-

In this tutorial, we will create a program that will transpose the taken matrix from the user. First, we will take the input size of the matrix and the elements from the user. Then we will use the for loop to traverse the matrix. At last, we will print the transpose of the matrix to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • mt[10][10]= it will hold the integer value.
  • rw = it will hold the integer value.
  • cl = it will hold the integer value.
  • i = it will hold the input integer value for loops.
  • j = it will hold the input integer value for loops.

Taking the size and the elements of the matrix from the user.

Traversing the given matrix.

Printing the Traversed Matrix.

C Program to find Upper Triangle Matrix

C Program to find Upper Triangle Matrix

In this tutorial, we will learn to create a C program that will find Upper Triangle Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

What is a matrix?

A matrix is a multidimensional phenomenon and is created with the help of a 2d array having multiple rows and columns.

Algorithm:-

With the help of this program, we can find Upper Triangle Matrix.

Program to find Upper Triangle Matrix:-

In this tutorial, we will create a multidimensional array with the help of C programming. First, we will take the size of the array from the user, and then we will take the input elements. Now we will create an upper triangle in the matrix by adding a zero in rows. At last, we will print the matrix triangle.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • rw = it will hold the integer value.
  • clm = it will hold the integer value.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Creating the upper right triangle from the matrix.

Printing the Upper Triangle Matrix.

C Program to Pass Pointers as the Function Arguments

C Program to Pass Pointers as the Function Arguments

In this tutorial, we will learn to create a C program that will Pass Pointers as the Function Arguments in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in c programming.

What is a Pointer?

The pointer in c language is the variable that can store the address of another variable and access the data of that variable. The pointers are very powerful terminology in programming.

Program description:-

In this tutorial, we will use the pointers in C language.  First, we will take the input numbers from the user in integer format. Then we will pass that number’s address to the function and the pointer will grab the value of the variables from their address. Then we will swap the value using a user-defined function. At last, we print the swapped values from that function.

With the help of this program, we can use Pointers as the Function Arguments.

Program to use functions with Pointers:-

 

Output:-

In the above program, we have first initialized the required variable.

  • x = it will hold the integer value.
  • y = it will hold the integer value.

Taking the two integer values from the user.

 

Swapping the numbers using the pointer and function.

Printing the output numbers after swapping.

C Program to Find Sum of series 1²+2²+3²+….+n²

C Program to Find Sum of series 1²+2²+3²+….+n²

In this tutorial, we will learn to create a C program that will Find the Sum of series 1²+2²+3²+….+n² using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Mathematical Functions in C Programming.

What is a Series?

The series is a number pattern from a starting point to a specific point, with a special difference between its two terms. The series can be of difference between the terms, the ratio between the term, or a specific logic between the two terms.

Programs to Find Sum of Series:-

In this tutorial, we will learn to create a program that will find the sum of the given series using a mathematical expression and the pre-defined functions. First, we will take the input from the user in the form of an integer value. Then we will calculate the sum of squares of the series using the predefined mathematical function and arithmetic expressions. At last, we will print the sum of the series.

Program Code:-

Output:-

In the above program, we have first initialized the required variable

  • no = it will hold the integer value.
  • sum = it will hold the integer value.

Taking the number of terms from the user.

Finding the sum of the square of the series.

 

Program Code for Printing the sum of squares of series.

C Program to Find Sum of series 1³+2³+3³+….+n³

C Program to Find Sum of series 1³+2³+3³+….+n³

In this tutorial, we will learn to create a C program that will Find the Sum of series 1³+2³+3³+….+n³ using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Mathematical Functions in C Programming.

What is a Series?

The series is a number pattern from a starting point to a specific point, with a special difference between its two terms. The series can be of difference between the terms, the ratio between the term, or a specific logic between the two terms.

Programs to Find Sum of Series:-

In this tutorial, we will learn to create a program that will find the sum of the given series using a mathematical expression and the pre-defined functions. First, we will take the input from the user in the form of an integer value. Then we will calculate the sum of the series using the predefined mathematical function and arithmetic expressions. At last, we will print the sum of the series.

Program Code:-

Output:-

In the above program, we have first initialized the required variable

  • no = it will hold the integer value.
  • sum = it will hold the integer value.

Taking the number of terms from the user.

Finding the sum of the series.

Program Code for Printing the sum of series.

C Program to Find Sum of Geometric Progression Series

C Program to Find Sum of Geometric Progression Series

In this tutorial, we will learn to create a C program that will Find the Sum of the Geometric Progression Series using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in C Programming.
  • Functions in C Programming.

What is Geometric Progression?

The Geometric progression is a series in mathematics that starts from a point and the second term is having a common ratio, and this series continues till the endpoint with the common ratio.

It means if the first term is 1 and then the ratio of 5 then the next term will be 5 then the next term will be 5*5.

Programs to Find Sum of Geometric Progression Series:-

In this program, First, we take the first term of the Geometric progression. Then we will take the total number of terms in G.P. At last we will take the common ratio from the user. Now we will generate the Geometric progression using the for loop and the mathematical expressions. Then will print the sum of the Geometric progression.

Program Code:-

Output:-

In the above program, we have first initialized the required variable

  • first_term = it will hold the integer value.
  • no = it will hold the integer value.
  • rt= it will hold the integer value.
  • tn = it will hold the float value.
  • i = it will hold the integer value to control the array.

Taking the first term, common ratio, and the number of terms from the user.

Generating the geometric progression using the loops and calculating the sum.

Program Code for Printing the sum of series.

C Program to Find Sum of Arithmetic Progression Series

C Program to Find Sum of Arithmetic Progression Series

In this tutorial, we will learn to create a C program that will Find Sum of Arithmetic Progression Series using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in C Programming.
  • Functions in C Programming.

What is Arithmetic Progression?

The arithmetic progression is a series in mathematics that starts from a point and the second term is having a common difference, and this series continues till the endpoint with the common difference.

Programs to Find Sum of Arithmetic Progression Series:-

In this program, First, we take the first term of the arithmetic progression. Then we will take the total number of terms in A.P. At last we will take the common difference from the user. Now we will generate the arithmetic progression using the for loop and the mathematical expressions. Then will print the sum of the arithmetic progression.

Program Code:-

 

Output:-

In the above program, we have first initialized the required variable

 

  • first_term = it will hold the integer value.
  • no = it will hold the integer value.
  • dis = it will hold the integer value.
  • tn = it will hold the integer value.
  • i = it will hold the integer value to control the array.

Taking the first term, common distance, and the number of terms from the user.

Generating the A.P. using the loops and calculating the sum.

 

Program Code for Printing the sum of series.