Category Archives: C Programs

C Programs

C Program to Insertion Sort Using Array

C Program to implement Insertion sort Algorithm

In this tutorial, we will learn to create a C program that will do insertion sort using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.
  • Creating and Using the user-defined function in C programming.

What is Insertion Sort?

In every programming language, the sorting of data is a very important factor.  In C Language. Many different techniques for sorting are available to work with but in this tutorial, we will focus on the Insertion Sort Technique.

In this technique, the work is done by inserting the smaller number to the first position. i.e. 

the first and second number is sorted if the number is big then it is moved to the right and if it is small the moves to the left.

 

Algorithm

 

 

Program For Insertion Sort

 

Output:-

In the above program, we have first declared and initialized a set of variables required in the program.

  • n = it will hold the size of the array.
  • x[]= it will hold the elements in an array.

Function to print array:-

Insertion sort function

Main function body

 

C Program to Access Elements of an Array Using Pointer

C Program to Access Elements of an Array Using Pointer

In this tutorial, we will learn to create a C program that will Access Elements of an Array Using Pointer using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.
  • Using pointer in C programming.

Access Elements of an Array Using Pointer:-

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. First will take the elements of an array from the user.  Then will pass the elements address to the pointer and the will print the elements of array /Access Elements of an Array Using Pointer with the help of C Programming Language.

Pointer is a variable that can store the address of another variable.

Algorithm:-

Program:-

Access Elements of an Array Using Pointer.

 

Output:-

The above program we have to first initialize the required variable.

 

  • array = it will hold the elements in an array.
  • i = it will hold the integer value to control array.

Creating Pointer.

  • *ptr = it will hold the address of elements in a array.

Taking input from the user in an array elements in array.

Printing using array.

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 the element of Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

The reverse of the array:-

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. First will take the number of elements of an array from the user. Then will take the elements from the user for the array. And at last, we will reverse the array using C Programming Language.

Algorithm:-

Program:-

To Reverse element from the array

Output:-

In the above program we have first initialized the required variable

n

  • arr = it will hold the elements in an array.
  • n = it will hold the number of  elements in an array.
  • i = it will hold the integer value to control the array.
  • size = it will hold the size of array.

Taking input from the user in an array number of elements in array

Taking input from the user in an array elements in array

Program Code

C Program to Find Minimum Element in Array

C Program to Find Minimum Element in Array

In this tutorial, we will learn to create a C program that will find the Minimum Element in Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.
  • Creating and Using the user-defined function in C programming.

The minimum value of array:-

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. The index value of the array start’s from “0” if the array is having size 5 i.e. a[5] = { 1, 2, 3, 4, 5 } values can be stored in that array. Now the a[0] = 1 , a[1] = 2, a[2] = 3, a[3] = 4, a[4] = 5. On the array, we can do many operations with the help of the c language.

We will find the minimum size element with the help of conditional statements.

Algorithm:-

Program:-

To find minimum value element from array

Output:-

In the above program we have first initialized the required variable

  • location = it will hold the location of array elements.
  • array[100] = it will hold the elements in an array.
  • i = it will hold the integer value to control the array.
  • size = it will hold the size of the array.

Printing output of the program to user

Program Code

C Program to Find Maximum Element in Array

C Program to Find Maximum Element in Array

In this tutorial, we will learn to create a C program that will find the maximum Element in Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.
  • Creating and Using the user-defined function in C programming.

The Maximum value of array:-

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. The index value of the array start’s from “0” if the array is having size 5 i.e. a[5] = { 1, 2, 3, 4, 5 } values can be stored in that array. Now the a[0] = 1 , a[1] = 2, a[2] = 3, a[3] = 4, a[4] = 5. On the array, we can do many operations with the help of the c language.

We will find the maximum size element with the help of conditional statements.

Algorithm:-

Program:-

To find the Maximum value element from the array

 

Output:-

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

  • arr[100] = it will hold the elements in an array.
  • i = it will hold the integer value to control the array.
  • no= it will hold the size of the array.

Printing output of the program to the user

Input Size.

Input elements of the array.

Calculating the maximum value.

C Program to Calculate Average Using Arrays

C Program to Find Average an Array

In this tutorial, we will learn to create a C program that will average the elements of Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

Average of the array:-

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. First will take the number of elements of an array from the user. Then will take the elements from the user for the array. And at last, will total the values and divide them from the number of elements of the array to find the average using C Programming Language.

Algorithm:-

Program:-

To find the Average value element from the array

 

Output:-

In the above program we have first initialized the required variable

  • arr = it will hold the elements in an array.
  • n = it will hold the number of elements in an array.
  • i = it will hold the integer value to control the array.
  • sum= it will hold the sum of the array.
  • avg= it will hold the average of the array.

Taking input from the user in an array number of elements in the array.

Taking input from the user in array elements in the array.

Sum of the array.

Average of Array.

C Program For Merging Of Two Arrays

C Program to Merge Two Arrays

In this tutorial, we will learn to create a C program that will merge two different array the element of Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

Merging of two arrays:-

As we all know array is a collection of similar data type elements. In array only one variable is declared which can store multiple values. First will take the number of elements of array1 from the user. Then will take the number of elements of array2 from the user. Then will take the elements from the user for the array1 and as well as for array 2.

And at last, will merge the values and of the different arrays into a single array using C Programming Language.

Algorithm:-

Program:-

To find Merge the two array element into single array

 

 

Output:-

The above program we have first initialize the required variable

  • a[] = it will hold the elements in a array1.
  • b[] = it will hold the elements in a array2.
  • c[] = it will hold the elements in a array3.
  • n1 = it will hold the number of  elements of array1.
  • n2 = it will hold the number of  elements of array2.
  • n3 = it will hold the number of  elements of array3.
  • i = it will hold the integer value to control array using for loop.

Taking input from the user for array1 as well as array2 and merging them.

Printing merged array.

C Program to Insert an Element in an Array

C Program to Insert an Element in an Array

In this tutorial, we will learn to create a C program that will Insert an Element in an Array using C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

Insert an Element of Array

As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. First will take the number of elements of an array from the user. Then will take the elements from the user for the array. And at last, we will insert the array element by asking the user with the help of C Programming Language.

Algorithm:-

Program:-

To insert an element in the array

Output:-

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

  • arrah[] = it will hold the elements in an array.
  • no = it will hold the number of elements in an array.
  • i = it will hold the integer value to control the array.
  • value = it will hold the value to be inserted.
  • position = it will hold the location for the insert element of the array.

Taking input from the user in an array number of elements in the array

Taking input from the user in array elements in the array

Insert location for elements.

 

inert value.

Printing output

C Program to Reverse a Sentence Using Recursion

C Program to Reverse a Sentence Using Recursion

In this tutorial, we will learn to create a C program that will C Program to Reverse a Sentence Using Recursion in C programming.

Prerequisites

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

  • Operators in C Programming.
  • Usage of Conditional statements.
  • Basic Input and Output function in C Programming.
  • Basic C programming.

Reverse a Sentence Using Recursion

In c programming, we have many predefined functions to workout with. The c language allows us to take long inputs from the users i.e. statements, these string values in the c programming language can be manipulated with the help of many predefined functions available for working.

The string manipulation functions can be applied to the variables or to be exact on the input statements. Available functions in a c programming language can make it easier to work with the strings.

With the help of these functions, we can reverse a string. Change a string to an upper case string or to a lower case string and many more.

Algorithm:-

Program to Reverse a sentence using the recursion:-

Output:-

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

  • c = string type variable that will hold the value of the input sentence.

Input strings from the user.

Scanning the input for the program.

Reverse printing function for the sentence.

Main Function of the program.

C Program to Concatenate Two Strings Using Pointers

C Program to Concatenate Two Strings Using Pointers

In this tutorial, we will learn to create a C program that will Concatenate Two Strings Using Pointers in C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

Concatenate Two Strings Using Pointers

As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values. First will take the number of elements of string 1 from the user. Then will take the number of elements of string 2 from the user. Then will take the elements from the user for string 1 and as well as for string 2. And concatenate them using the pointer.

With the help of this program, we can Concatenate Two Strings Using Pointers.

Algorithm:-

Program to Concatenate Two Strings Using Pointers:-

 

Output:-

The above program we have first initialize the required variable.

  • string1[20] = it will hold the string value.
  • string2[20] = it will hold the string value.
  • i = it will hold the integer value.
  • j = it will hold the integer value.
  • *str1 = pointer type variable 1.
  • *str2 = pointer type variable 2.

Input strings from the user.

While loop body for concatenating the strings using the pointers and printing the concatenated string.

 

C Program to Compare Two Strings Without Using strcmp

C Program to Compare Two Strings Without Using strcmp

In this tutorial, we will learn to create a C program that will Compare Two Strings Without Using strcmp in C programming.

Prerequisites

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

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic of C programming.
  • For loop and its concepts in C Programming.
  • Conditional Statements in C Programming.

Compare Two Strings Without Using strcmp

As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values. First will take the elements of string 1 from the user. Then will take the elements of string 2 from the user. Then will compare the two taken strings without using the predefined functions. i.e. compare them without using the strcmp function.

With the help of this program, we can Compare Two Strings Without Using strcmp

Algorithm:-

Program to Compare Two Strings Without Using strcmp:-

 

 

Output:-

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

  • string1[100] = it will hold the string value.
  • string2[100] = it will hold the string value.
  • i = it will hod the integer value that will control the for loop

Taking Input string 1 from the user.

Taking Input string 2 from the user.

Printing Output without using the strcmp function which is available in c language.

C Program to Concatenate Two Strings Without Using strcat

C Program to Concatenate Two Strings Without Using strcat

In this tutorial, we will learn to create a C program that will Concatenate Two Strings Without Using strcat in C programming.

Prerequisites

Before starting with this tutorial we assume that you are 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.

Concatenate Two Strings Without Using strcat.

As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values. First will take the number of elements of string 1 from the user. Then will take the number of elements of string 2 from the user. Then will take the elements from the user for string 1 and as well as for string 2. And concatenate them using the Without Using strcat .

With the help of this program, we can Concatenate Two Strings Without Using strcat

Algorithm:-

Program to Concatenate Two Strings Using Without Using strcat :-

 

Output:-

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

  • string1[100] = it will hold the string value.
  • string2[100] = it will hold the string value.
  • i = it will hold the integer value.
  • j = it will hold the integer value.
  • string3 = it will hold the string value.

Input strings.

While loop body for the first string to another.

While loop body for the second string to another.

Printing Output.