Category Archives: C Programs

C Programs

C Program to Sort Array in Ascending Order

C Program to Sort Array in Ascending Order

In this tutorial, we will learn to create a C program that will Sort Array in Ascending 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 Ascending Order

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

Algorithm:-

Program description to Sort Array in Ascending 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 ascending order. At last, we will print that sorted array elements.

With the help of this program, we can Sort Array in Ascending 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 ascending order.

C Program to Find Sum of all Elements in an Array

C Program to Find Sum of all Elements in an Array

In this tutorial, we will learn to create a C program that will Find Sum of all 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.

Program description to Find Sum of all Elements in an Array.

In this program, we will first take the input array size and the elements from the user. Then we will add all the elements of the array. At last, we will print that sum of numbers.

With the help of this program, we can Find Sum of all Elements in an Array.

Program Code:-

Output:-

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

  • sum = it will hold the integer value for the sum of numbers.
  • a[] = it will hold the integer value of the input elements.
  • 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 sum.

C Program to Find Sum of Even and Odd Numbers in an Array

C Program to find Sum of Even and Odd numbers in an Array

In this tutorial, we will learn to create a C program that will find Sum of 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 an Even number?

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

What is an Odd number?

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 find Sum of 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 and add them separately. At last, we will print that numbers.

With the help of this program, we can Print Sum of Even & Odd numbers in an Array.

Program Code:-

Output:-

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

  • evensum = it will hold the integer value for the sum of numbers.
  • oddsum = it will hold the integer value for the sum of the odd numbers.
  • 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 sum.

C Program to find Sum of Even and Odd numbers in a Given Range

C Program to find Sum of Even and Odd numbers in a Given Range

In this tutorial, we will learn to create a C program that will find Sum of Even and Odd numbers in a Given Range 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 Even number?

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

What is an Odd number?

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

Program to find Sum of Even and Odd numbers in a Given Range.

In this program, we will first take the input range from the user. Then we will separate the even and odd numbers from that range and add them separately. At last, we will print that numbers.

With the help of this program, we can Print Sum of Even & Odd numbers.

Program to Print Sum of Even & Odd Numbers:-

Output:-

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

  • evensum = it will hold the integer value for the sum of numbers.
  • oddsum = it will hold the integer value for the product of the numbers.
  • i = it will hold the integer value.
  • no = it will hold the integer value of the input.

Input number from the user.

Program Logic Code.

Printing output sum.

C Program to Find Unique Elements in an Array

C Program to Find Unique Elements in an Array

In this tutorial, we will learn to create a C program that will Find Unique Elements in an Array 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.
  • Conditional Statements in C programming.
  • Array 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.

Algorithm:-

Program to Find Unique Elements in an 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 find the unique elements of the array. Printing the unique elements of the array.

With the help of this program, we can Print the unique Array Elements.

Program description:-

 

Output:-

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

  • n = it will hold the integer value.
  • i = it will hold the integer value.

Taking the input number of elements and the elements of the array.

Finding the unique elements in the array.

Printing the unique elements of the array.

C Program to Implement Quick Sort Algorithm

C Program to implement Quick-sort Algorithm

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

The Quicksort is a sorting algorithm based on dividing the array and arranging where an array is divided into sub-arrays and the number is taken from the array itself. Then We will sort that array using the quick sort method.

Program For Quick Sort:-

In this program, we will perform the quick-sort algorithm

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.

Printing the unsorted array.

Performing the quick sort on an unsorted array.

The printing sorted array

C Program to Remove All Duplicate Characters in a String

C Program to Remove All Duplicate Characters in a String

In this tutorial, we will learn to create a C program that will Remove All Duplicate Characters in a String 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.
  • Conditional Statements in C programming.

What is a string?

As we all know the String is a collection of characters and words. The word is a collection of alphabets. For string, only one variable is declared which can store multiple values. The String can consist of all the typeable data it means Digits, Alphabets, Symbols, etc.

Algorithm:-

Removing All Duplicate Characters in a String

In this program first, we will take input strings from the user. Then we will find the length of the string. Then we will remove All the duplicate characters from that string. Printing the result string.

Let us take the example program from the below code for Removing All Duplicate Characters in a String.

Program Code:-

 

Output:-

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

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

Input string from the user for the program.

Removing duplicate characters from the string.

Printing output String.

C Program to Toggle Case of all Characters in a String

C Program to Toggle Case of all Characters in a String

In this tutorial, we will learn to create a C program that will Toggle the Case of all Characters in a String 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.
  • For loop in C programming.
  • Conditional Statements in C programming.

What is a String?

The String is a collection character. The character is a single entity in the English language or in any word. These characters can be any alphabets in lower case or upper case.

The lower case means the small letters. And the upper case means the capital letters of the English language.

For Example:-

In the string “Hello”, there are five characters, they are as follows

Here,

‘H’ is a character in the Upper case.

‘e’ is a character in the lower case.

‘l’ is a character in the lowercase.

‘l’ is a character in the lower case.

‘o’ is a character in the lowercase.

Algorithm:-

Program to Toggle Case of all Characters in a String:-

First, we will take the input string from the user. Then will pass that String in the conditional statements to check and change the case of every character. It means the lower case character will be converted to the upper and upper case to lower.

With the help of this program, we can Toggle the Case of all Characters of the String.

Program Code:-

Output:-

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

  • str1[100] = it will hold the String value for the input.
  • i = it will hold the integer value for the loop.

Input String from the user.

Toggle all characters.

Printing toggled String.

C Program to Reverse a String

C Program to Reverse a String

In this tutorial, we will learn to create a C program that will Reverse a String 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.
  • Usage of Conditional statements in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C Programming.

What is reversing a string?

A string is a collection of words, numbers, and symbols. The String can be any sentence of English Language. Reversing a string means writing the sentence or a string in reverse order from last to first.

Algorithm:-

Program Description for Reversing the String:-

In this program, We will first take the input string from the user in string format. Then we will find the length of that string using strlen(); after that reversing that string using the for-loop. Storing the reversed sentence in a variable. Printing the reversed string from the program.

With the help of the below, code we will Reverse the String.

Program Code:-

Output:-

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

  • str = string type variable that will hold the value of the input sentence.
  • i = it will hold the integer value.
  • len  = it will hold the integer value.
  • flag = it will hold the temporary integer value.

Input string from the user for the program.

Reverse The string.

Printing the reversed string.

C Program to Reverse Order of Words in a String

C Program to Reverse Order of Words in a String

In this tutorial, we will learn to create a C program that will Reverse the Order of Words in a String 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.
  • Usage of Conditional statements in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.

What is a string?

A string is a collection of words, numbers, and symbols. The String can be any sentence of English Language.

Algorithm:-

Program Description for Reversing the Order of Words in a String:-

In this program, We will first take the input sentence from the user in string format. Then we will reverse that sentence using a short amount of code using the for-loop. Storing the reversed sentence. Printing the reversed sentence from the loop.

With the help of the below, code we will Reverse the Order of Words in a String.

Program Code:-

Output:-

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

  • str = string type variable that will hold the value of the input sentence.
  • i,j = it will hold the integer value.
  • firstpoint, lastpoint = it will hold the integer index value.

Input string from the user for the program.

Reverse The string sentence.

Printing the reversed string.

C program to find Number is Divisible by 5 and 11

C program to find Number is Divisible by 5 and 11

In this tutorial, we will learn to create a C program that will find Number is Divisible by 5 and 11 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.
  • Conditional Statements in C programming.
  • Arithmetic operations in C Programming.

Program to find Number is Divisible by 5 and 11 or not:-

The program will find whether a Number is Divisible by 5 and 11 or not. In c programming, it is possible to take numerical input from the user and check if that number is divisible by 5 and 11 or not with the help of a very small amount of code.

In this program, we will take a number in the input from the user to check if it’s prime or not.

With the help of this program, we can Check whether a Number is Divisible by 5 and 11 or not.

Algorithm:-

Program to find that the number is divisible by 5 and 11:-

 

Output:-

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

  • no= it will hold the integer value of the input.

Input message for the user for the integer value.

Program Logic Code.

Printing output number is divisible or not.

C Program to Print Hollow Mirrored Rhombus Star Pattern

C program to Print Hollow Mirrored Rhombus Star Pattern

In this tutorial, we will learn to create a C program that will print a Hollow Mirrored Rhombus Star Pattern 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.
  • For loop in C programming.
  • Conditional Statements in C programming.

Algorithm:-

Program description Printing Hollow Mirrored Rhombus:-

In this program, we will first take the input number of rows by the user. Then we will pass that input size to the nested for loop to draw the Hollow Mirrored Rhombus pattern.

Printing the Hollowed Mirrored Rhombus pattern filled with stars. Let’s take the below example for the problem.

Program Code:-

 

Output:-

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

  • N = it will hold the integer value for the input.
  • i = it will hold the integer value.
  • j = it will hold the integer value.

Input the number of rows for the Hollowed Mirrored Rhombus.

Program Code.

Printing output pattern using c programming.