Category Archives: C Programs

C Programs

C Program to Reverse an Array

C Program to Reverse an Array.

In this tutorial, we will learn to create a C program that will reverse an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Reversing an Array:-

In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. Then we will copy elements of the array. After that, we will reverse the array using the for-loop. Then we will print the reverse of the original array to the user.

With the help of this program, we can be reverse an Array.

Program Code:-

Output:-

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

  • array1[] = it will hold the integer value.
  • i = it will hold the integer value.
  • j = it will hold the integer value.
  • num = it will hold the integer value.
  • array2[] = it will hold the integer value.

Taking the size of the array and the elements.

Program Code to Reverse an Array.

Printing output of the program.

C Program to Search for Element in an Array.

C Program to Search for Element in an Array.

In this tutorial, we will learn to create a C program that will Search for Element in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Search for Element in an Array.

In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. Then we will take the element to search in the array. After that, we will search that element in the array. Then we will print the result element with its position to the user.

With the help of this program, we can be Search for Element in an Array.

Program Code:-

Output:-

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

  • arr[] = it will hold the integer value.
  • i = it will hold the integer value.
  • size = it will hold the integer value.
  • found = it will hold the integer value.

Taking the size of the array and the elements.

Program Code to find the element in the array.

Printing output of the program.

C Program to Find Second largest Number in an Array

C Program to Find Second-largest Number in an Array

In this tutorial, we will learn to create a C program that will Find the Second-largest Number in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

 Find the Second-largest Number in an Array.

In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. After that, we will compare every element of the array and   Find the Second-largest Number in an Array. Then we will print the result Second-largest element of the array to the user.

With the help of this program, we can be Find the Second-largest Number in an Array.

Program Code:-

Output:-

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

  • arr[] = it will hold the integer value.
  • i = it will hold the integer value.
  • size = it will hold the integer value.
  • max2 = it will hold the integer value.

Taking the size of the array and the elements.

Program Code to find the second-largest elements in the array.

Printing output of the program.

C Program to Find Smallest Number in an Array

C Program to Find Smallest Number in an Array

In this tutorial, we will learn to create a C program that will Find the Smallest Number in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable. The array can be both single as well as multidimensional.

 Find the Smallest Number in an Array.

In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. After that, we will compare every element of the array and   Find the Smallest Number in an Array. Then we will print the result smallest element of the array to the user.

With the help of this program, we can be Find the Smallest Number in an Array.

Program Code:-

Output:-

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

  • no = it will hold the integer value.
  • i = it will hold the integer value.
  • a[30] = it will hold the integer value.
  • smll = it will hold the integer value.

Taking the size of the array and the elements.

Program Code to find the smallest elements in the array.

Printing output of the program.

C Program to Count Total Number of Duplicate Elements in an Array

C Program to Count Total Number of Duplicate Elements in an Array

In this tutorial, we will learn to create a C program that will Count the Total Number of Duplicate Elements in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable. The array can be both single as well as multidimensional.

Count Total Number of Duplicate Elements in an Array.

In this program, First, we will first take the size of the array from the user. Then we will take the elements of the array from the user. After that, we will Count the Total Number of Duplicate Elements in an Array. Then we will print the result array to the user.

With the help of this program, we can be Count the Total Number of Duplicate Elements in an Array.

Program Code:-

Output:-

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

  • j = it will hold the integer value.
  • i = it will hold the integer value.
  • arr[10] = it will hold the integer value.
  • count = it will hold the integer value.

Taking the size of the array and the elements.

Program Code to find the duplicate elements.

Printing output of the program.

C example to Copy an Array to another

C example to Copy an Array to another

In this tutorial, we will learn to create a C program that will Copy an Array to another 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Copy an Array to another.

In this program, First, we will first take the size of the arrays from the user. Then we will take the elements of the array 1 and 2 from the user. After that, we will Swap Two Arrays Without Using Temp Variable. Then we will print the result array.

With the help of this program, we can be Swap Two Arrays Without Using Temp Variable.

Program Code:-

Output:-

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

  • arry1[] = it will hold the integer value.
  • arry2[] = it will hold the integer value.

Finding the size of the arrays and the elements.

Program Logic Code.

Printing output of the program.

C Program to Swap Two Arrays Without Using Temp Variable

C Program to Swap Two Arrays Without Using Temp Variable

In this tutorial, we will learn to create a C program that will Swap Two Arrays Without Using Temp Variable 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Swap Two Arrays Without Using Temp Variable.

In this program, First, we will first take the size of the arrays from the user. Then we will take the elements of the array 1 and 2 from the user. After that, we will Swap Two Arrays Without Using Temp Variable. Then we will print the result array.

With the help of this program, we can be Swap Two Arrays Without Using Temp Variable.

Program Code:-

Output:-

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

  • j = it will hold the integer value.
  • i = it will hold the integer value.
  • a[10] = it will hold the integer value.
  • b[10] = it will hold the integer value.

Taking the size of the arrays and the elements.

Program Logic Code.

Printing output of the program.

C Program to Perform Arithmetic Operations on Multi-Dimensional Arrays

C Program to Perform Arithmetic Operations on Multi-Dimensional Array

In this tutorial, we will learn to create a C program that will Perform Arithmetic Operations on a Multi-Dimensional Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Perform Arithmetic Operations on a Multi-Dimensional Array.

In this program, First, we will first take the size in the format of rows and columns of the arrays from the user. Then we will take the elements of the array 1 and 2 from the user. After that, we will perform the arithmetic operations on the elements for the array. Then we will print the results of that array.

With the help of this program, we can be performing the arithmetic operations of the Arrays.

Algorithm:-

Program Code:-

 

Output:-

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

  • j = it will hold the integer value.
  • i = it will hold the integer value.
  • a[10] = it will hold the integer value.
  • b[10] = it will hold the integer value.

Taking the size of the arrays and the elements.

Program Logic Code.

Printing output of the program.

C Program to Perform Arithmetic Operations on One Dimensional Array

C Program to Perform Arithmetic Operations on One Dimensional Array

In this tutorial, we will learn to create a C program that will Perform Arithmetic Operations on One Dimensional Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Algorithm:-

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable.

Perform Arithmetic Operations on One Dimensional Array.

In this program, First, we will first take the size of the arrays from the user. Then we will take the elements of the array 1 and 2 from the user. After that, we will perform the arithmetic operations on the elements for the array. Then we will print the results of that array.

With the help of this program, we can Perform Arithmetic Operations on One Dimensional Array.

Program Code:-

 

Output:-

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

  • Size = it will hold the integer value.
  • i = it will hold the integer value.
  • a[10] = it will hold the integer value.
  • b[10] = it will hold the integer value.

Taking the size and elements of the arrays.

Program Logic Code.

Printing output of the program.

C Program to find the Number of Elements in an Array

C Program to find the Number of Elements in an Array

In this tutorial, we will learn to create a C program that will find the Number of Elements in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

Algorithm:-

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable. The array can be both single as well as multidimensional.

Program to find the Number of Elements in an Array.

In this program, we will first take the input array size and the elements from the user. Then we will find the number of elements in the array using a predefined function. After that, we will store the number of elements in that array into a variable. At last, we will print the number of elements in that array.

With the help of this program, we can find the Number of Elements in an Array

Program Code:-

 

Output:-

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

  • arr[] = it will hold the integer value of the array and its elements.

Finding the size of that array.

Program Logic Code.

Printing output of the program.

C example to Count Even and Odd Numbers in an Array

C example to Count Even and Odd Numbers in an Array

In this tutorial, we will learn to create a C program that will Count Even and Odd Numbers in an Array 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is Even and Odd number?

A number is said to be an even number when that number is divided by two into two equal whole numbers. A number is said to be an odd number when that number is divided by two into two, not equal whole numbers.

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable. The array can be both single as well as multidimensional.

Program to Count Even and Odd Numbers in an Array.

In this program, we will first take the input array size and the elements from the user. Then we will separate the even and odd numbers from that array. After that, we will count the even as we as odd valued elements. At last, we will print that number of even and odd elements.

With the help of this program, we can Count Even and Odd Numbers in an Array.

Program Code:-

 

Output:-

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

  • Even_Count = it will hold the integer value.
  • Odd_Count = it will hold the integer value.
  • i = it will hold the integer value.
  • Size = it will hold the integer value of the input.

Input number of elements from the user.

Program Logic Code.

Printing output of the program.

C Program to Sort Array in Descending Order

C Program to Sort Array in Descending Order

In this tutorial, we will learn to create a C program that will Sort Array in Descending Order 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is An array?

The array is a collection of similar data types. An array can store multiple values with different indexes in memory by using a single variable. The array can be both single as well as multidimensional.

Sort Array in Descending Order.

In this tutorial, we will sort the array in descending order from the biggest to the smallest value of the array.

Algorithm:-

Program description to Sort Array in Descending Order.

In this program, we will first take the input array size and the elements from the user. Then we will sort all the elements of the array in descending order. At last, we will print that sorted array elements.

With the help of this program, we can Sort Array in Descending Order.

Program Code:-

Output:-

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

  • j = it will hold the integer value.
  • arry[] = it will hold the integer value of the input elements.
  • i = it will hold the integer value.
  • n = it will hold the integer value of the input.

Input number of elements from the user.

Program Logic Code.

Printing output in Descending order.