Category Archives: C++ Programs

c plus plus programs

C++ Program to Find Quotient and Remainder

C++ Program to Find Quotient and Remainder

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

What are Quotient and Remainder?

In the divide operation, the remaining part in the operation is a remainder. The answer part we get after the operation is a quotient.

Algorithm to Find Quotient and Remainder:-

Program to Find Quotient and Remainder:-

The integer values are used with operators to perform the arithmetic in programming. The divide operation is done in mathematics to get the remainder and quotient value. First, we will take two numbers and divide them to find the quotient and remainder.

With the help of this program, we can take input and Find Quotient and Remainder.

Program to Find Quotient and Remainder:-

Output:-

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

  • divisor = it will hold the input number value from the user.
  • dividend= it will hold the input number value from the user.
  • qtnt = it will hold the integer value of the Quotient.
  • rmdr = it will hold the integer value of the Remainder.

Taking Input divisor and dividend from the user.

Calculating the quotient and the remainder.

Printing the output.

C++ Program to Find Size of int, float, double and char in Your System

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

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++ Functions with No Arguments and No return value

C++ Functions with No Arguments and No return value

In this tutorial, we will learn to create a C++ program that will use Functions with No Arguments and No return 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.
  • Functions in C++ programming.

What are functions in C++?

In every programming language, there are many types of functions available. There are two major types of functions in C++ programming.

  1. Predefined functions.
  2. User-defined functions.

In user-defined functions there are four types:-

  • Function with no argument and no return value
  • Function with no argument but the return value
  • User-defined Function with argument but no return value
  • User-defined Function with argument and return value

 

Algorithm:-

Program using Functions with No Arguments and No return value.

In this program, we will create a function that will print the symbols using a user-defined function with no return type and no arguments. With the help of this program, we can print the “*” of the above function type.

Program Code:-

Output:-

Creating the user-defined function with no arguments and no return type.

Body of the user-defined function.

Calling the user-defined function.

Body of the main function of the program.

C++ Program to Demonstrate Use of Ternary Operator

C++ Program to Demonstrate Use of Ternary Operator

In this tutorial, we will learn to create a C++ program that will Demonstrate Use of Ternary Operator 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.

What is a Ternary Operator?

In the C++ programming language, the ternary operator is also known as the conditional operator and can be used to replace if…else conditional statements at some places.

Algorithm:-

Program to Demonstrate Use of Ternary Operator:- 

In this program, we will use the ternary operator instead of if…else conditional statement. For checking the input with the conditions and printing the input marks are in pass or fail criteria.

With the help of this program, we can take input and calcualtion.

Program:-

Output:-

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

  • marks = it will hold the integer value.
  • result= it will hold the string value.

Taking Input numbers from the user.

Calculating the result.

Printing the output.

C++ Program to Find Sum and Average of Two Numbers

In this tutorial, we will learn to create a C++ program that  will Find Sum and Average of Two number  using C++ programming.

Prerequisites

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

  • Operators.
  • Data type in c++.
  • Basic input/output.
  • Basic c++ programming.

C++ Program to Find Sum and Average of Two Numbers

In this program we will find sum and average of two number  given by user . We would first declared and initialized the required variables. Next, we would prompt user to input numbers .Later we will addition and average of numbers.

Output

C++ Program to Find Sum and Average of Two Numbers

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

  • a = it will hold first value.
  • b = it will hold second value.
  • add=it will hold value after adding a and b.
  • avg=it will hold average of numbers.

This is one of the basic program in C++ and generally for the understand the basic structure of C++. Here we will  take two numbers as a input from user and calculate it’s addition and  finding average of these two number.

First of all we take  numbers as input from user and store the values in variable a and b respectively.

And now we will ad these two number add=a+b. and the result store in add variable shown in below image.

After that we will calculate average of these two numbers avg=a+b/2 or avg=add/2.

In our  program we have taken two numbers as a input from the user and then calculate it’s Addition 

and average .

C++ Program to Add Two Numbers

C++ Program to Add Two Numbers

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

What is addition?

The addition in mathematics is the sum of two numbers. The arithmetic operations are done using the arithmetic operators. These operators are used between two arithmetic operands or between two numbers.

Program to Add Two Numbers:- 

In this tutorial, we will create a program that will add the two numbers using an addition operator. We will first take two numbers in input and then we will add them and store the value in the third variable.

As we all know the integer, float, or double data types in c++ programming. In c++ programming, we can take the input from the user in numbers format. In today’s program, we will take input in number format. Secondly, we will add the number with the help of a small program. The numbers are the most useful terminology in any programing language. For number/arithmetic manipulation in c++ programming, there are many predefined functions available.

Numbers are the most useful data types in any programming language. The integer values are used with operators to perform the best operations in programming.

With the help of this program, we can take input and Add Two Numbers.

Algorithm to Add the numbers:-

 

Program to Add Two Numbers:-

Output:-

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

  • fno = it will hold the input number value from the user.
  • sno = it will hold the input number value from the user.
  • sum = it will hold the sum value of the numbers.

Taking Input numbers from the user.

Calculating the sum of two numbers.

Printing the output.

C++ Program to Print Integer

C++ Program to Print Integer

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

What is an integer?

The integer is a positive or negative whole number including zero. These are the number real numbers.

Algorithm to print the Integer:-

Program to Print Integer 

As we all know the integer, float, or double value in c++ programming. In c++ programming, we can take the input from the user in number format. In this program, we will take input in integer format. The second will display the integer with the help of a small program. The integer are the most useful terminology in any programing language. For number/arithmetic manipulation in c++ programming, there are many predefined functions available.

Integers are the most useful data types in any programming language. The integer values are used with operators to perform the best operations in programming.

With the help of this program, we can take input and Print Integer.

Program to Print Integer:-

Output:-

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

  • no = it will hold the input number value from the user.

Taking Input from the user.

Printing the data in the output in the number format.

 

C++ Program to Print String

C++ Program to Print String

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

What is String?

A string is traditionally a sequence of characters, symbols. Every English letter used for input-output in any function is a string. The output messages are also a set of strings.

Algorithm to print string in the output:-

Program to Print String

As we all know the string is a collection of characters in c++ programming. In c++ programming, we can take the input from the user in string format. In today’s program, we will take input in string format. The second will display the string with the help of a small program. The String is the most useful terminology in any programing language. For string manipulation in c++ programming, there are many predefined functions available.

With the help of this program, we can take input and Print String.

Program to Print String:-

Output:-

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

  • strary = it will hold the input string value from the user.

Taking Input from the user.

Printing the data in the output in the string format.

The Program Code for the main method.

C++ Program to Print Number Entered by User

C++ Program to Print Number Entered by User

In this tutorial, we will learn to create a C++ program that will Print Number Entered by Users 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.

The printing of numbers from the user at a console is very essential. Number if can’t be printed on the screen then the user can never get the output for the calculation. That’s why number printing is important.

Algorithm to print the number entered by users in the output:-

Program to Print Number Entered by Users

In this program, we will take input numbers from the user and then we will print the number on the console with the help of a short c++ program.

With the help of this program, we can take input and Print Number Entered by Users.

Program to Print Number Entered by Users:-

Output:-

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

  • no = it will hold the input number value from the user.

Taking Input from the user.

Printing the data in the output in the number format.

 

C++ Program to Print Hello World

C++ Program to Print Hello World

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

Printing a message:-

Message passing is a very important feature for object-oriented programming. Here in this program, we will print the message to the user for hello world.

Algorithm to Print Hello World in the output:-

Program to Print Hello World

The string is a collection of characters in c++ programming. The string is used for sending messages on the screen. In c++ programming, we can take the input from the user in string format. In this program, we will define input in string format. The second will print the string “Hello World” with the help of a small program. The String is the most useful datatype in any programing language.

Program to Print Hello World:-

Output:-

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

  • strary = it will hold the input string value from the user.

Printing the data in the output in the string format.

The Program Code for the main method.