Category Archives: C Programs

C Programs

C Program to Remove First Occurrence of a Character in a String

C Program to Remove First Occurrence of a Character in a String

In this tutorial, we will learn to create a C program that will Remove the First Occurrence of a Character 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 the First Occurrence of a Character in a String

In this program first, we will take input string from the user. Then we will take the character to be removed from the user. Then will be Removing the First Occurrence of the Character in that String. Printing the result string.

Let us take the example program from the below code for Removing the First Occurrence of the Character in that String.

Program Code:-

 

Output:-

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

  • strg[100] = it will hold the string value.
  • chr = it will hold the string value.
  • len = it will hold the integer value.
  • i = it will hold the integer value.

Input string from the user for the program and Take the input character from the user to remove.

Removing that character from the string.

Printing output String.

C Program to Remove Last Occurrence of a Character in a String

C Program to Remove Last Occurrence of a Character in a String

In this tutorial, we will learn to create a C program that will Remove the Last Occurrence of a Character 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 the Last Occurrence of a Character in a String

In this program first, we will take input strings from the user. Then we will take the character to be removed from that string. Then will be Removing the Last Occurrence of the Character in that String. Printing the result string.

Let us take the example program from the below code for Removing the Last Occurrence of the Character in that String.

Program Code:-

 

Output:-

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

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

Input string from the user for the program and Take the input character from the user to remove.

Removing that character from the string.

Printing output String.

C Program to find the size of int, float, double, and char

C Program to find the size of int, float, double, and char

In this tutorial, we will learn to create a C program that will Find the Size of int, float, double, and char in Your System 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.
  • Arithmetic operations in C Programming.

What is a data type?

A data type, in every programming language, specifies which type of value a variable is going to hold in the program. i.e. integer, character, float, double.

Algorithm for the program to view data type size:-


 

Program to check the size of predefined data types in C programming.

In every programming language, there are many predefined datatypes available. Today we will create a program that will print the size of integer, character, float, and double in bytes. Because every datatype variable reserves the size in memory for each type of variable.

With the help of this program, we can find the size of the above data types.

Program Code:-

 

Output:-

Printing the size of character data type using the size of function.

Integer type printing its size by using sizeof function.

Printing the size of float data type using the size of function.

Printing the size of double data type using the size of function.

C Program to Print an Integer, Character, and Float Value

In this tutorial, we will learn to create a C program that will Print an Integer, Character, and Float Value 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.
  • Arithmetic operations in C Programming.

What is a data type?

A data type, in every programming language, specifies which type of value a variable is going to hold in the program. i.e. integer, character, float, double.

Algorithm for the program to Print an Integer, Character, and Float Value:-

Program Print an Integer, Character, and Float Value.

In every programming language, there are many predefined datatypes available. Today we will create a program that will print the integer, character, float, and double in output. By taking input values from the user.

With the help of this program, we can Print an Integer, Character, and Float Value.

Program Code:-

 

Output:-

Taking Input values from the user.

Printing the values.

 

C Program to find Largest of Three Numbers

C Program to Find Largest of Three Numbers

In this tutorial, we will learn to create a C program that will find the Largest of Three Numbers 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.
  • Conditional statement in C programming.

Algorithm:-

Program to Find Largest of Three Numbers

In c programming, it is possible to take numerical input from the user to find the Largest of  Three Numbers. Then we will pass those numbers to the conditional statements to find the largest number. At last, we will print the largest number from the given three numbers.

With the help of this program, we can find the Largest Number Among Three Numbers.

Program code to find the largest of Three Numbers:-

Output:-

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

  • no1 = it will hold the integer value.
  • no2 = it will hold the integer value.
  • no3 = it will hold the integer value.

Input numbers for the program.

 

Program Logic Code.

Printing output for the greatest number.

C Program to find Largest of Two Numbers

C Program to Find Largest of Two Numbers

In this tutorial, we will learn to create a C program that will find the Largest of Two Numbers 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.
  • Conditional statement in C programming.

Algorithm:-

Program to Find Largest of Two Numbers

In c programming, it is possible to take numerical input from the user to find the Largest of  Two Numbers. Then we will pass those numbers to the conditional statements to find the largest number. At last, we will print the largest number from the given Two numbers.

With the help of this program, we can find the Largest Number Among Two Numbers.

Program code to find the largest of Two Numbers:-

Output:-

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

  • no1 = it will hold the integer value.
  • no2 = it will hold the integer value.

Input numbers for the program.

 

Program Logic Code.

Printing output for the largest number from two numbers.

C program to Convert String to Lowercase

C Program to Convert String to Lowercase

In this tutorial, we will learn to create a C program that will Convert String to Lowercase 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 Convert String to Lowercase

First, we will take the input string from the user. Then will pass that String in the conditional statements to check and convert it into the lower case String.

With the help of this program, we can convert that String to lower case.

Program Code:-

Output:-

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

  • str = it will hold the String value for the input.
  • i = it will hold the integer value for the loop.

Input String from the user.

Checking the given String and converting it into a lower case string.

Printing Lower case String.

C program to Convert String to Uppercase

C Program to Convert String to Uppercase

In this tutorial, we will learn to create a C program that will Convert String to Uppercase 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 Convert String to Uppercase

First, we will take the input string from the user. Then will pass that String in the conditional statements to check and convert it into the  Upper case String.

With the help of this program, we can convert that String to upper case.

Program Code:-

Output:-

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

  • str = it will hold the String value for the input.
  • i = it will hold the integer value for the loop.

Input String from the user.

Checking the given String and converting it into an upper case String.

Printing uppercase String.

C program to print Natural Numbers from 1 to N

C Program to print Natural Numbers from 1 to N

In this tutorial, we will learn to create a C program that will print Natural Numbers from 1 to 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.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is a Natural number?

The natural numbers are all those positive numbers from 1 to infinity. The set of natural numbers contains all whole positive numbers. The number with decimal points does not come under the natural numbers.

Algorithm:-

Program to print Natural Numbers from 1 to N.

In this program, we will first take the point up to which we want to generate the series from the user. Then we will generate the series up to that point. At last, we will print that natural numbers in sequence.

With the help of this program, we can print Natural Numbers from 1 to N.

Program Code:-

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.

Input number from the user.

Program Logic Code.

Printing output.

C program for Simple Calculator

C Program for Simple Calculator

In this tutorial, we will learn to create a C program. After that, will perform Simple Calculator 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.
  • Switch Case in C programming

Program for Simple Calculator:- 

In today’s tutorial, we will create a program. That will do the Addition, Subtraction, Multiplication, and Division operations with the help of Arithmetic operators in C programming.

Algorithm:-

Program Code:-

Output:-

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

  • op = it will hold the input character value from the user.
  • first = it will hold the input number value from the user.
  • second = it will hold the input number value from the user.

Taking Input numbers from the user.

Performing simple calculations.

Printing the output.

C Program for Total, Average, and Percentage of Five Subjects

C Program for Total, Average, and Percentage of Five Subjects

In this tutorial, we will learn to create a C program that will find the Total, Average, and Percentage of Five Subjects 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.
  • Arithmetic operations in C Programming.

What is a percentage of numbers?

The percentage of all the marks is calculated by adding the total marks. And then we will divide it by the maximum marks and multiplied by 100.

What is the average of numbers?

The average of numbers in mathematics means that all the numbers are added and then the sum of all the numbers is divided by the total number of objects.

It means if there are 5 subject marks as follows {60,60,60,80,70} then the average will be:-

average = 60+60+60+80+70/5

average = 60.

Algorithm:-

Program to calculate total, Average, and Percentage of Five Subjects.

In this program, we will first take the marks of all five subjects from the user. And then we will add them to find the total marks. Now the total will be divided by the number of subjects to find the average.  Then the total will be divide by maximum marks and multiply by 100. Last, we will print the outputs.

Example using the below program.

Program Code:-

Output:-

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

  • eng = it will hold the float value.
  • chem = it will hold the float value.
  • phy = it will hold the float value.
  • math = it will hold the float value.
  • comp = it will hold the float value.
  • total = it will hold the float value.
  • average = it will hold the float value.
  • percentage = it will hold the float value.

Input number from the user.

Program Logic Code.

Printing output.

C program to calculate Sum and Average of N Numbers

C Program to calculate Sum and Average of N Numbers

In this tutorial, we will learn to create a C program that will calculate Sum and Average of N Numbers 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 the average of numbers?

The average of numbers in mathematics means that all the numbers are added and then the sum of all the numbers is divided by the total number of objects.

It means if there are 4 number as follows {2,4,6,8} then the average will be:-

average = 2+4+6+8/4

average = 5.

What is a Natural number?

The natural numbers are all those positive numbers from 1 to infinity. The set of natural numbers contains all whole positive numbers. The number with decimal points does not come under the natural numbers.

Algorithm:-

Program to calculate Sum and Average of N Numbers.

In this program, we will first take the point up to which we want to sum from zero to that point from the user. Then we will generate the series up to that point. At last, we will add those numbers and calculate the average of those numbers & will print the sum of n natural numbers and the average.

With the help of this program, we can Find Sum & Average of n natural numbers.

Program Code:-

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.
  • sum = it will hold the integer value.
  • avg = it will hold the integer value.

Input number from the user.

Program Logic Code.

Printing output.