Category Archives: C++ Programs

c plus plus programs

C++ Program to Find Largest Element of an Array

In this tutorial, we will learn to create a C++ program that will Find Largest  Elements of 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.
  • looping statements.
  • Basic input/output.
  • Basic c++ programming
  • For Loop.
  • Array.

What is array?

An Array is a collection variable elements  that can store multiple values in a single variable of same type.In Computer Science,an array is a data structure, or simply an array, is a data structure consisting of a collection of elements.

C++ Program to Find Largest Element of an Array

In this program we will find Largest Element in an Array. We would first declared and initialized the required variables. then we would prompt user to input elements of array .Later we will find the Biggest element in an Array.

Output

C++ Program to Find Largest Element of an Array

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

  • a[5] = it will hold entered elements.
  • max =it will give largest number in an array.
  • i = for iteration.

In our program, we will take 5 values form user in an array ,

after taking these values we will find the maximum number in  an array.

First of all we will take 5 values from user  in variable a[5].

After that we will initialize max=a[0] i.e first element of a an array.

Now we compare the value of max with each and every value present in array a[5]. While comparing, if the value of max  is less than in condition, then the value of max  (value which is greater than max values) swapped and gets initialized to max and at the end we will get the maximum value within the  array in max.

C++ Program to Calculate Average of Numbers Using Arrays

C++ Program to Calculate Average of Numbers Using Arrays

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 numbers:-

The average number means the sum of all the terms, divided by the number of terms. The resultant will be the average of numbers.

Algorithm:-

Program to Calculate Average of Numbers Using Arrays:-

As we all know array is a collection of similar data type elements. we can perform many different operations on arrays in c++ programming. In today’s program, we will take an array as an input and then we will find the average of all of its elements.

Program:-

To find the Average value element from the array

Output:-

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

  • num = 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 float value for the sum of the array.
  • avg= it will hold the float value for 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.

 

Calculating the Average of Array printing the output number.

C++ program to find even and odd elements in array

C++ program to find even and odd elements in the array

In this tutorial, we will learn to create a C++ program that will find even and odd elements in the 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.
  • Conditional Statements in C++ programming.
  • Arithmetic operations in C++ Programming.

Even and Odd Numbers:-

The Even numbers are those numbers that are completely divisible by 2. which means the reminder should be zero. And the Odd numbers are those numbers that are not completely divisible by 2.

Algorithm:-

Program to find even and odd elements in the array

In C++ programming, it is possible to take integer input from the user and find even and odd elements in the array with the help of a very small amount of code. We will pass that array to a condition to find even and odd numbers from the array.

With the help of the below program, we can Find Even & Odd elements in the array.

Program Code:-

Output:-

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

  • arry[20] = it will hold the integer value.
  • even[20] = it will hold the integer value.
  • odd[20] = it will hold the integer value.
  • i = it will hold the integer value.
  • j = it will hold the integer value.
  • k = it will hold the integer value.
  • size = it will hold the integer value.
Taking input from the user the size and the elements of the array.

Stored Data in the array.

Program Logic Code and print the even & odd numbers Separately.

C++ Program to Delete Array Element

C++ Program to Delete Array Element

In this tutorial, we will learn to create a C++ program that will delete 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.

Program for Delete the element of Array:-

An array is a collection of similar data type elements. In today’s program, we will take an array in input from the user and then we will take the element for deleting from the array. After deleting the element from the array we will reprint the array.

Algorithm for program:-

Program code:-

To Delete an element from the array

Output:-

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

  • arr[10] = it will hold the elements in an array.
  • tot = it will hold the number of elements in an array.
  • i = it will hold the integer value to control the array.
  • Elem = it will hold the location for delete element size of the array.

Taking input from the user in an array of elements.

Deleting the array element.

Printing the Program Code

 

C++ Programs to Insert Element in Array

C++ Program to Insert Element in Array

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

Insert Element in Array:-

In this tutorial, we will make a program that will insert the element in the array using c++ programming. First will take the five elements of an array from the user. Then will take the new elements from the user for inserting in the array. And at last, we will insert that element at the end of the array.

Algorithm:-

Program Code:-

Output:-

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

  • i = it will hold the integer value.
  • arr[6] = it will hold the elements in an array.
  • elem = it will hold the integer value that will be inserted in the array.

Taking input from the user:-

 

New elements from the user.

 

Taking input elements to add from the user.

C++ Program to Calculate Compound Interest

In this tutorial, we will learn to create a c++ program that will calculate compound interest using c++ programming.

Prerequisites

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

  • Arithmetic operators.
  •  Basic input/output.
  • Looping statements.
  • Operator precedence.
  • Data types.

What Is Compound Interest?

Compound Interest is a interest that obtain by adding the interest of each year to the principal sum and then calculating the interest on the updated amount.

CI is interest earned from the original principal +  accumulated interest.

Formula for Compound Interest is.


Here,
P is principle amount.
R is the rate in Percent %.
T is time in year.

C++ Program to Calculate Compound Interest.

In this program we will find Compound Interest ,We would first declared and initialized the required variables. Next, we would prompt user to input principle,rate and time (p, r, t) and  applying Compound Interest formula to calculate Compound Interest. Now let’s have look at the code .

Output

C++ Program to Calculate Compound  Interest

Here the Logic behind to calculate compound interest.

Here is the  logic to find compound interest.

    • First of all we take 3 values of  principle,time and  rate.

    • We store the given inputted values in variable p,rand t respectively.
    • Now passing all three values to know formula of CI which is.

    First of all the values of  p,r and t is given by user at compile time and with the help of power function we will calculate the ci of given years.Finally, we print the resultant value of ci.

C++ Program to Calculate Simple Interest

In this tutorial, we will learn to create a c++ program that will find Simple Interest  using c++ programming

Prerequisites

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

  • Basic C++ programming.
  • Operators.
  • Basic input/output.
  • Basic mathematics calculation.
  • Precedence.

What Is Simple interest ?

Simple interest is the interest amount given by the bank within a year to user or taken by bank or firm from consumer  for a particular principal amount of money at some rate of interest. Simple Interest is a method of calculating the interest for a loan/principal amount.

Here:=>
SI = Simple Interest.
P = Principal.
R = Rate of interest (in percentage).
T = Time Interval (in years).

C++ Program to Calculate Simple Interest.

In this program we will print find Simple Interest . We would first declared and initialized the required variables. Next, we would prompt user to input the Principal,Rate and time . Later we will find Simple Interest.

Output

C++ Program to Calculate Simple Interest

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

  • si = For calculating si.
  • p=  for principal.
  • r= for rate of interest.
  • t= for time interval in a year.

First of all we declare  variables si,p,r and t then by prompting user to give Principal Rate and time . Here in this program we get principal rate and time from user.

After accepting values of  principle, rate and time from user , we apply the formula to calculate simple interest is which  is si= (principle x rate x time) / 100. and  after calculating si we will print the Simple Interest. 

Simple Interest is a method used by mostly in Banking and Economic sectors to calculate the interest charges on loans or in saving account by Bank or Economic Sectors.

C++ Program to Calculate Student Grade

In this tutorial, we will learn to create a c++ program that will Calculate Student Grade using c++ programming

Prerequisites

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

  • Basic C++ programming.
  • Operators.
  • Basic input/output.
  • Basic mathematics calculation.
  • Precedence.

C++ Program to Calculate Student Grade .

In this program we will Calculate Student Grade. We would first declared and initialized the required variables. Next, we would prompt user to input Subject  numbers. Later we will find the grade of that student.

Output

C++ Program to Calculate Student Grade

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

  • m = holds value of math.
  • p = holds value of physics.
  • c = holds value of chemistry
  • h = holds value of Hindi.
  • e= holds value of English.
  • total = calculate sum of value.
  • per= it will hold percentage.

In the next statement user will be prompted to enter the five subject marks  which will be assigned to variable ‘m’,’p’,’c’,’h’,’e’.

after that we add all  given values  in variable total ( total =m+p+c+h+e ).Now, we calculated the percentage (per=total/5).Grades must be calculated based on following conditions.
If percentage > 85 then A grade.

elseIf (percentage < 85 && percentage >= 75) print B grade


else If percentage < 75 && percentage >= 50 print C grade


else If percentage > 30 && percentage <= 50 print D grade


else percentage <30 print fail.
First we take subject marks of  student as inputted we find the total and percentage.and after that for grade compare the percentage with different criteria as mentioned in the program.

C++ Program to Calculate Percentage Of Students Marks

In this tutorial, we will learn to create a c++ program that will calculate Percentage Of students using c++ programming

Prerequisites

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

  • Operators.
  • Basic input/output.
  • Basic c++ programming.

C++ Program to Calculate entered 5 subjects marks and calculate percentage.

In this program we will create a program in which user enter the marks of five subjects and calculate percentage.We would first declared and initialized the required variables. Next, we would prompt user to input the number of terms. Later we will calculate percentage of given number of terms.
And you will learn how to find percentage of the five subjects in C++ language.
using for loop.

Output

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

  • m = holds value of math.
  • p = holds value of physics.
  • c = holds value of chemistry
  • h = holds value of Hindi.
  • e= holds value of English.
  • total = calculate sum of value.
  • per= it will hold percentage.

In this  C++ program to calculate Percentage of Five Subjects .

In the first  cout<<“” statement will ask the user to enter the 5 subjects number.

then we add all 5 given  value  in variable total ( total =m+p+c+h+e ).


Now, we calculated the percentage (per=total/5).

And we will get the required output.This program allows user to enter five values of five different  subjects. And then calculate the Total and Percentage of those Five Subjects.

C++ Program to Calculate area of rectangle

In this tutorial, we will learn to create a c++ program that find Area of Rectangle using c++ programming

Prerequisites

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

  • C++ Operators.
  • Functions.
  • Basic input/output.
  • Basic c++ programming.

What Is Area?

Area measures the space inside any shape.
The extent or measurement of a surface or piece of land.
Area term is  used to define the amount of space cover up by a 2D shape or surface.

C++ Program to Calculate area of rectangle

In this program , we will calculate Area of Rectangle of a given Length and Width .First of all user will be prompted to enter Length and Width and afterword passing these value to function to calculate Area of Rectangle.

Output

C++ Program to Calculate area of rectangle

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

  • length = it will hold entered length.
  • width = it will hold entered width.
  • l=  hold value of length.
  • w=hold value of width.

Now let us look process of find area of rectangle step by step.

      • first or all take length and width from user.
      • then pass these value  of length and width to function AreaOfRect(length, width).
      • where in function  we calculate area of rectangle using formula (a=l*w).

    • after, calculating area function returns us the area of rectangle or given length and width,
    • Finally in main function we will print the area of rectangle of given values.

C++ Program to Convert Fahrenheit to Celsius

In this tutorial, we will learn to create a c++ program that Convert Fahrenheit to Celsius using c++ programming

Prerequisites

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

  • Operators.
  • looping statements.
  • Basic input/output.
  • Basic c++ programming
  • For Loop.
  • String.

What Is Temperature ?

Temperature is a quantity that measured the freezing and boiling point of water. Which is measured in different scales like Celsius and Fahrenheit.
In Celsius scale, the boiling point of water is 100°C, and the freezing point is at 0°C, while in the Fahrenheit scale the boiling point of water is 212°F and freezing point is at 32°F.

C++ Program to Convert Fahrenheit to Celsius.

In this program we will convert temperature from Fahrenheit to Celsius. We would first declared and initialized the required variables. Next, we would prompt user to input the value in Fahrenheit. Later we will Convert the values into Celsius.

To convert values from Fahrenheit to Celsius we will use following Formula:

C = (F – 32)*(5/9)where, F is temperature in Fahrenheit and C is temperature in Celsius.

Output

C++ Program to Convert Fahrenheit to Celsius

Logic to find Fahrenheit to Centigrade

First of all Take the Fahrenheit  temperature in f
Then calculate c = 5 * (f – 32) / 9.
return C.

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

  • f = it will hold Fahrenheit value.
  • c= it will hold Celsius value.

And  in the next statement user will be prompted to enter value in Fahrenheit and  which will be assigned to variable ‘f’.

After that with the help of  formula we will convert the value in to Celsius.

As you can see in above program, we first take value in Fahrenheit  as input from user. Then convert the value of Fahrenheit in to Celsius using above conversion equation and print the Temperature in Celsius.

C++ Program to Convert Celsius to Fahrenheit

In this tutorial, we will learn to create a c++ program that Convert Celsius to Fahrenheit  using c++ programming

Prerequisites

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

  • Operators.
  • looping statements.
  • Basic input/output.
  • Basic c++ programming
  • For Loop.
  • String.

What Is Temperature ?

Temperature is a quantity that measured the freezing and boiling point of water. Which is measured in different scales like Celsius and Fahrenheit.
In Celsius scale, the boiling point of water is 100°C, and the freezing point is at 0°C, while in the Fahrenheit scale the boiling point of water is 212°F and freezing point is at 32°F.

C++ Program to Convert Celsius to Fahrenheit.

In this program we will convert temperature from Celsius to Fahrenheit . We would first declared and initialized the required variables. Next, we would prompt user to input the value in Celsius. Later we will Convert the values into Fahrenheit.

To convert values from Celsius  to Fahrenheit  we will use following Formula:

f = (c * 9 / 5) + 32 where, F is temperature in Fahrenheit and C is temperature in Celsius.

Output

C++ Program to Convert Celsius to Fahrenheit

Logic to find Centigrade to Fahrenheit

First of all Take the Celsius Temperature in c
Then calculate f = (c * 9 / 5) + 32.
return f.

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

  • f = it will hold Fahrenheit value.
  • c= it will hold Celsius value.

And  in the next statement user will be prompted to enter value in Celsius  and  which will be assigned to variable ‘c‘.

 

After that with the help of  formula we will convert the value in to Fahrenheit .

 

As you can see in above program, we first take value in Celsius  as input from user. Then convert the value of Celsius into Fahrenheit  using above conversion equation and print the Temperature in Fahrenheit .