Category Archives: C Programs

C Programs

C Print Series upto n Term

C Program to Print Series upto n Term.

In this tutorial, we will learn to create a C program that will Print Series up to n Term 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.
  • For loop in c programming.

As we all know the c programming is a very powerful language. In the c programming language, we have many pre-defined functions for arithmetic operations. But today we will print the series up to the given number using the c programming language.

With C programming we can make many arithmetics series with just a little code.

With the help of this program, we can Print Series up to n Term.

Algorithm:-


 

Program to Print Series up to n Term:-

 

 

Output:-

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

  • i = it will hold the integer value for the loop.
  • No = it will hold the integer value of number input.

Display message to Take input number from the user and scan the input number.

Program code to print the list up to the given number.

 

C Program to Check Leap Year or Not

C Program to Check Leap Year or Not.

In this tutorial, we will learn to create a C program that will Check Leap Year or Not 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.
  • String functions in c programming.

Check Leap Year or Not.

As we all know the c programming is a very powerful language. In the c programming language, we have many pre-defined functions for arithmetic operations. but today we will check whether the given number is a leap year or not with the help of the c programming language.

With the help of this program, we can Check Leap Year or Not.

Algorithm:-


 

Program to Check Leap Year or Not:-

 

 

Output:-

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

  • yr = it will hold the integer value of number input.

Taking input number from the user.

Calculating and Printing output of the program.

C Program to Sort Word in String in Ascending Order

C Program to sort Word in String in Ascending Order

In this tutorial, we will learn to create a C program that will sort Word in String in Ascending Order 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.
  • For loop in c programming.
  • String functions of c programming.

Sort Word in String in Ascending Order

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, we will take the input string from the user.

Then we will sort that string using the for a loop.

With the help of this program, we can sort Word in String in Ascending Order.

Algorithm:-

 

Program to Sort Word in String in Ascending Order:-

 

Output:-

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

  • str[100] = it will hold the string value.
  • len = it will hold the integer value.
  • i = it will hold the integer value.
  • j = it will hold the integer value.
  • flag = it will hold the string value.

Input strings from the user.

Scanning string from the user.

Getting the length of the string.

Sorting the string using for loop.

Printing the output.

C Program to find number is even or odd

In this tutorial, we will learn to create a program to find whether a given number is even or odd using C programming.

Prerequisites

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

  • C Operators
  • C if else statement

How to find number is even or odd

An integer number that is exactly divisible by 2 is known as even number, example: 0, 8, -24. Programmatically, we can check number is even or add using modulus (%) operator. If modulus 2 of any integer number is equals to 0 then, the number is even otherwise odd.

Program to find number is even or odd

In this program we will find a number entered by user is even or odd using modulus (%) operator. We would first declared and initialized the required variables. Next, we would prompt user to input an integer number. Later in the program we will check number entered by user is even or odd using modulus (%) operator. We will then display message number is even or odd.

Output 1:-

C-Program-to-check-number-is-even-or-odd-11

Output 2:-

C-Program-to-check-number-is-even-or-odd-2

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

  • num = it holds the input integer number

In the next statement user will be prompted to enter an integer number to check is assigned to variable ‘num’. In the next statement we check modulus 2 of integer number is equals to 0 or not i.e. if(num % 2 == 0) then the number is even otherwise odd. Now, we will be displaying the number is even or odd.

Program to check number is even or odd Using Bitwise operator

In this program we will check a number entered by user is even or odd using bitwise(&) operator. We would first declared and initialized the required variables. Next, we would prompt user to input an integer number. Later in the program we will check number entered by user is even or odd using bitwise(&) operator. We will then display message number is even or odd.

Output 1:-

C-Program-to-check-number-is-even-or-odd-11

Output 2:-

C-Program-to-check-number-is-even-or-odd-2

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

  • num = it holds the input integer number

In the next statement user will be prompted to enter an integer number to check is assigned to variable ‘num’. In the next statement we check number is even or odd using bitwis(&) operator i.e. if(num & 1 == 1) then the number is odd otherwise even. Now, we will be displaying the number is even or odd.

C Program to implement Shell sort Algorithm

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

Prerequisites

Before starting 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 Shell Sort?

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

The Shell Sort is an evolved version of the insertion sort. Well will pick the data from an index point of array is and swap it with a faraway position index. Then data interchange between 2 locations from the array and doesn’t need to be too close to be swapped.

Program For Shell Sort

 

Output:-

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

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

After this, we make the main function for our program and define variables calling functions.

The Shell Sorting function body

The printing array function body

C Program to implement Radix sort Algorithm

C Program to implement Radix sort Algorithm

In this tutorial, we will learn to create a C program that will do Radix 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 Radix sort?

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

The Radix Sort is a simple and easy technique. It first makes the group of similar values from a big given array then those small groups are again re-arranged and placed at the deserving positions.

Program for Radix sort

Output:-

In the above program we have first initialized the required variable and passed them to other functions for the Radix sort

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

Now the program will call the print function to display the elements.

After this, the program executes the next function & finds the largest number from the elements of the array.

Now the function to do count sort first

Now, the final step radix function to process the data.

As a result we got the sorted array.

By calling the print function.

C Program to implement Bubble sort Algorithm

C Program to implement Bubble sort Algorithm

In this tutorial, we will learn to create a C program that will do Bubble 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 Bubble 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 Bubble Sort Technique.

In this technique, the elements of the array are sorted from the very first value by swapping from starts first & second and going to till the end. Now, this process will go on until the array is completely arranged.

Algorithm for optimized bubble sort

 

Program For Bubble Sort

Output :-

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

  • no = it will hold the size of the array.
  • x[5]= it will hold the elements in an array.
  • flag= it will hold the temporary values.
  • i= it will hold the integer value to control the array.
  • j= it will hold the integer value to control the array.

Function to print on the terminal/console.

Function to implement the bubble sort.

 

The main function to perform and navigate the program cleanly.

 

C Program to implement Selection sort Algorithm

C Program to implement Selection Sort Algorithm

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

Prerequisites

Before starting 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-define function in C programming.

What is Selection 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 Selection Sort Technique.

It’s the most simple sorting technique. In this technique, we will select the smallest array element and place it in the first position the second on the second position.

Algorithm


 

Program For Selection Sort

 

Output:-

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

  • no = it will hold the size of the array.
  • x[]= it will hold the elements in an array.
  • flag= it will hold the temporary values.
  • i= it will hold the integer value to control the array.
  • j= it will hold the integer value to control the array.

Function to print on the terminal/console.

Function to implement the bubble sort.

The main function to perform and navigate the program cleanly.

C program to implement MERGE sort Algorithm

C Program to Merge sort Algorithm

In this tutorial, we will learn to create a C program that will do Merge 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.
  • While loop in C programming.
  • For loop in C Programming.
  • Creating and Using the user-defined function in C programming.

What is Merge 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 Merge Sort Technique.

In this technique, we will divide the array into smaller chunks until there is only one element left. Then we will merge the chunks and gets a sorted array.

Algorithm

 

Program For Merge Sort

 

 

Output:-

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

  • no = it will hold the size of array.
  • x[]= it will hold the elements in a array.

Subarray sorting merging Function Body:-

  • i = it will hold the integer value to control the array.
  • j = it will hold the integer value to control the array.
  • k= it will hold the integer value to control the array.
  • LeftArray = it will hold the left array values. 
  • RightArray = it will hold the left array values.

 

Merge Sorting Function Body:-

Print Array Function body:-

The main function to perform and navigate the program cleanly.

C Program to implement Insertion sort Algorithm

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 implement HEAP sort Algorithm

C Program to implement HEAP Sort Algorithm

In this tutorial, we will learn to create a C program that will do HEAP sorting 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 Heap 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 Heap Sort Technique.

This technique is opposite to the selection sort technique. Here, we will select the highest value and put it in last, and create a heap for maximum values. This processing is continued till the smallest value is found.

Algorithm

Heap Sort

MaxiHeap (arry)

MaxiHeapify(arry,i)

 

Program For Heap 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.
  • arr[] = it will hold the value of the array.
  • x[]= it will hold the elements in an array.

Function to print array:-

Function For Heaping

HEAP sort function

Main function body

C Program to implement Bucket sort Algorithm

C Program to implement Bucket sort Algorithm

In this tutorial, we will learn to create a C program that will do Bucket 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 Bucket 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 BucketSort Technique.

In this technique, we will create multiple small groups containing a range of elements. Then these groups are back joint again and the sorted array is formed.

Algorithm

 

Program For Bucket 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.
  • i = it will control the for loop for the array.

Function to print array:-

Function for getting the max number.

Bucket sort function.

Main function body.