<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8506354445069520893</id><updated>2026-03-26T10:08:41.814+05:00</updated><category term="How To Install Turbo C++ 3.0 - IDE"/><category term="Sorting Algorithms Plus Programs"/><category term="#define directive"/><category term="Advantages of Algorithms"/><category term="Algorithm and Program of Hours Conversion"/><category term="All Even Numbers Between Two Numbers Inclusive"/><category term="Area and Circumference of Circle Program in C Plus Plus"/><category term="Basic Structure of a C++ Program"/><category term="Benefits of Flowcharts"/><category term="Brief History of C++"/><category term="Bubble Sort Algorithm Trace Steps on Sample Data and C++ Program"/><category term="C Plus Plus Program Display Odd Numbers between 1 to 10"/><category term="C Plus Plus Program Reverse Number Conversion"/><category term="C Plus Plus Program To display numbers from 10 down to 1"/><category term="C Plus Plus Program to Calculate Factorial of Number Using Do While Loop"/><category term="C Plus Plus Program to Swap Values of Two Variables"/><category term="C Plus Plus program to calculate square and cube of a number"/><category term="C Plus Plus program to display 1 to n numbers"/><category term="C Plus Plus program to find count of digits in a given number"/><category term="C++ Editor Free Download"/><category term="C++ Examples of algorithm writing"/><category term="C++ Program Algorithms"/><category term="C++ Program Area of Triangle When Three Sides Given"/><category term="C++ Program Development Cycle"/><category term="C++ Program Factorial of given number input by user at run time"/><category term="C++ Program Logic Building-Program 1"/><category term="C++ Program Temperature Conversion Celsius To Fahrenheit Formula"/><category term="C++ Program To Calculate Area and Circumference of Circle in C Plus Plus Program"/><category term="C++ Program To Calculate Product of Digits of Given Number"/><category term="C++ Program To Count Number of Digits in a Given Number"/><category term="C++ Program To Find Product of Digits of Given Number"/><category term="C++ Program To Find Sum of Digits of Given Number"/><category term="C++ Program To Input Base"/><category term="C++ Program to Calculate Bonus on Salary Grade Wise"/><category term="C++ Program to Find GCD of two integer numbers"/><category term="C++ Program to swap values of two variables without third variable"/><category term="C++ Programming Algorithms"/><category term="C++ Variables"/><category term="C++ Variables declaration"/><category term="C++ program Check Prime or Composite Number"/><category term="C++ variable names"/><category term="Calculate Area"/><category term="Calculate Bonus Salary C Plus Plus Program"/><category term="Calculate and display all numbers and sum from 1 to N"/><category term="Calculate and display even all numbers and sum from 1 to N"/><category term="Compile and Run Your First C++ Program"/><category term="Computer Science"/><category term="Convert a Number into Reverse Number C++ Program"/><category term="Convert age years into days"/><category term="Declaring Variables in C++"/><category term="Display 1 to 10 numbers by for loop"/><category term="Display Even 1 to 10 by FOR Loop"/><category term="Display Factorial of given Number"/><category term="Display N Fibonacci Terms in C C++"/><category term="Do While ~ For ~While loop"/><category term="Do while loop flow chart example"/><category term="Download Free C++ IDE for Windows OS"/><category term="Download Pre-installed Turbo C++ 3.0 IDE Free"/><category term="Download and Install Turbo C++ Full Screen Windows 7 Vista"/><category term="Easy C++ tutorial on do while loop"/><category term="Easy Explaination of DO While loop"/><category term="Easy Reverse Number C++ Program"/><category term="Easyway How To Write a Program in C++ for Calculating Area of Triangle When base and height is given"/><category term="Easyway How to Write a C++ Program for C++ Program Temperature Conversion Celsius To Fahrenheit Formula"/><category term="Example Algorithms for C Plus Plus Programming"/><category term="Example Solved Algorithms"/><category term="Explain  Insertion Sort Algorithm"/><category term="Explain Different Types of Iterative Looping Structures"/><category term="Explain Variables in Programming C++"/><category term="Explain Variables in Programming langugages"/><category term="Explain Working of Nested For Loop With Example Code"/><category term="Explanation of Fibonacci Series n Terms Program"/><category term="Factorial By For Loop Statement"/><category term="Factorial Program by do while loop"/><category term="Factorial of number by Recursion Method"/><category term="Features of C++ Programming Language"/><category term="Fibonacci c programming"/><category term="Fibonacci c++ program logic"/><category term="Fibonacci program"/><category term="Find Area of Circle"/><category term="Find HCF or GCF or HCD or GCD of Two Whole Numbers"/><category term="First C++ Program Writing"/><category term="Flow Chart Examples"/><category term="Flow Chart Symbols"/><category term="Flowcharting By Example"/><category term="Flowcharts in Computer Programming"/><category term="GCD Program in See Plus Plus (C++)"/><category term="Height of Triangle"/><category term="How To Draw a Flowchart"/><category term="How To Find Circumference of Circle While Area is given"/><category term="How To Run C++"/><category term="How To Start Computer Programming"/><category term="How To Start Turbo C++ IDE"/><category term="How To Write"/><category term="How to declare variables in C++"/><category term="Input radius and find area of circle"/><category term="Insertion Sort Algorithm"/><category term="Insertion Sort Algorithm Example"/><category term="Insertion Sort Program Source Code"/><category term="Insertion Sort Program using C++"/><category term="Introduction To Programming: Page-1"/><category term="Introduction to C++"/><category term="Learn Algorithm Writing"/><category term="Lesson-1"/><category term="Naming Rules For C++ Variables"/><category term="Nested For Loop Programming Star Shapes"/><category term="OOP"/><category term="Object Oriented Programming"/><category term="Program"/><category term="Program Age Years To Days Convert"/><category term="Program Area of Triangle Algorithm Flowchart"/><category term="Program Average Algorithm and Flowchart"/><category term="Program Calculate Factorial of a Number"/><category term="Program Calculate Product of Digits of Given Number C Plus Plus"/><category term="Program Calculate Sum of Squares of Digits of Given Number"/><category term="Program Compute Sum of Cubes of Digits of User Supplied Number"/><category term="Program Count Number of Digits in a Given Number"/><category term="Program Display SUM All Odd from 1 To N"/><category term="Program Dividend Divisor Quotient Remainder"/><category term="Program Division"/><category term="Program Exchange Values Without Third Variable"/><category term="Program Factorial by While Loop Logic"/><category term="Program Find LCM of Two Numbers"/><category term="Program Find Out Quotient and Remainder"/><category term="Program Find Prime or Composite Number"/><category term="Program Find Sum of Digits of Given Number"/><category term="Program For Loop Display 1 To N Odd"/><category term="Program For Loop Display 1 To n Numbers"/><category term="Program For Loop Display 1 to 10"/><category term="Program For Loop Display 10 To 1 Numbers"/><category term="Program For Loop Display Odd 1 to 10"/><category term="Program Multiplication Table by While Loop"/><category term="Program Number Raise To the Power by Loop"/><category term="Program Print Alphabet Triangle"/><category term="Program Print Alphabet Triangle Downside"/><category term="Program Print Number Triangle Downside"/><category term="Program Print Number Triangle Reverse 5 To 1"/><category term="Program Print Number Triangle Upside"/><category term="Program Star Triangle Shape"/><category term="Program Sum of All Even Odd Numbers Between Two Numbers"/><category term="Program Sum of Even Numbers 1 To N"/><category term="Program Sum of Numbers 1 To N"/><category term="Program Temperature Conversion Algorithm Flowchart"/><category term="Program To Check Input for Perfect Number"/><category term="Program To Display All Even Numbers Between Two Numbers Inclusive"/><category term="Program To Display Even Numbers between 1 to 10"/><category term="Program To Find Circumference of Circle"/><category term="Program Variables"/><category term="Program to Find Out Square and Cube of a given Number"/><category term="Program to calculate power of a number by for loop"/><category term="Program to display all odd numbers between 1 and N"/><category term="Programming"/><category term="Properties of Algorithms"/><category term="Recursive Function Factorial in C++"/><category term="Reverse an input number by user C++ Program solution"/><category term="Role of Flowchart"/><category term="Rules for writing variable names"/><category term="Rules of variables in C++ program"/><category term="SUM of All ODD from 1 to N"/><category term="Show N Fibonacci Terms Program Sample"/><category term="Symbols Used in Flowcharts"/><category term="The Program Development Process"/><category term="The Role of Algorithms in Programming"/><category term="Use of Conditional Operator to check even odd number"/><category term="Use of Do While loop in C++ Programs"/><category term="Variable Declaration in C Plus Plus"/><category term="Variables in C++"/><category term="What is Computer Programming"/><category term="What is Nested For Loops"/><category term="What is a Computer Program"/><category term="Working of Nested Loops"/><category term="Working of While Loop With Examples"/><category term="Working of for loop statement with examples"/><category term="Write C++ Program To Calculate Bonus on Salary Grade Wise"/><category term="Write a C++ Program To Check a Number For Even Odd Using Conditional Operator Ternary Operator"/><category term="Write c++ program to add digits of a number"/><category term="Write program to calculate factorial by do while loop"/><category term="algorithm of temperature conversion program"/><category term="average c++ program"/><category term="basic data types in c plus plus"/><category term="c plus plus data types"/><category term="c++ flowchart"/><category term="c++ notes"/><category term="c++ program logic"/><category term="c++ program to calculate average"/><category term="c++ program with algorithm"/><category term="const qualifier"/><category term="data types"/><category term="define a constant"/><category term="do while loop with program examples in C++"/><category term="download c++ compiler free"/><category term="download free turbo c ide"/><category term="easy cpp notes"/><category term="easy turbo c++ programming"/><category term="easyway c++ program triangle area formula"/><category term="flowchart of temperature conversion"/><category term="free download turbo c++"/><category term="input age in years and convert into days with algorithm and flowchart"/><category term="learn c++ programming"/><category term="program area of circle"/><category term="program in C language to print all prime numbers between 1 and a given number n"/><category term="using constants in c plus plus program"/><category term="write programs in turbo c++"/><title type='text'>C++ Tutorial With Basic Programs for Beginners</title><subtitle type='html'>C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>83</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-1622787808658326216</id><published>2023-10-08T14:16:00.009+05:00</published><updated>2023-11-08T23:47:22.140+05:00</updated><title type='text'>Easy OOP Tutorial in C Plus Plus Programming</title><content type='html'>&lt;p&gt;Here is a simple and easy tutorial on Object-Oriented Programming (OOP) in &lt;a href=&quot;https://easycodebook.com/2023/11/cpp-programming-language-introduction/&quot; target=&quot;_blank&quot;&gt;C++ programming language&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;1. Introduction to OOP&lt;/p&gt;&lt;p&gt;2. Classes and Objects&lt;/p&gt;&lt;p&gt;3. Constructors and Destructors&lt;/p&gt;&lt;p&gt;4. Access Specifiers&lt;/p&gt;&lt;p&gt;5. Member Functions&lt;/p&gt;&lt;p&gt;6. Inheritance&lt;/p&gt;&lt;p&gt;7. Polymorphism&lt;/p&gt;&lt;p&gt;8. Encapsulation&lt;/p&gt;&lt;p&gt;9. Abstraction&lt;/p&gt;&lt;p&gt;10. Operator Overloading&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8NtCZTMjnHMWAolGQrknLI8EA7XQjLejhTyf90jqzi3I9XG0ztXE4gPKUYwHY28seue6XdT7tVYTO_ta-4jqQyX0Aq05xgmOzb8QWu0_WMeG_-fB_elol5RlCE-S8VJgvdshkQ-ODly7DDWTmZWz8mnhUVyj64C09SN4ZivMKa1T-Y2GBjLIo4hJdNC4r/s454/easy-oop-tutorial-in-c-plus-plus-programming.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Easy OOP Tutorial in C Plus Plus Programming&quot; border=&quot;0&quot; data-original-height=&quot;301&quot; data-original-width=&quot;454&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8NtCZTMjnHMWAolGQrknLI8EA7XQjLejhTyf90jqzi3I9XG0ztXE4gPKUYwHY28seue6XdT7tVYTO_ta-4jqQyX0Aq05xgmOzb8QWu0_WMeG_-fB_elol5RlCE-S8VJgvdshkQ-ODly7DDWTmZWz8mnhUVyj64C09SN4ZivMKa1T-Y2GBjLIo4hJdNC4r/s16000/easy-oop-tutorial-in-c-plus-plus-programming.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;1. Introduction to OOP&lt;/h2&gt;&lt;p&gt;Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize code. Learn about the key concepts and principles of OOP.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;2. Classes and Objects&lt;/h2&gt;&lt;p&gt;Learn how to define classes and create objects. Classes act as blueprints for objects, and objects are instances of those classes.&lt;/p&gt;&lt;p&gt;&amp;nbsp;In C++, classes and objects are fundamental concepts in object-oriented programming (OOP). They allow you to create structured, reusable code by defining blueprints for objects and then creating instances of those objects. Let&#39;s explore classes and objects in C++:&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Classes:&lt;/h3&gt;&lt;p&gt;A class in C++ is a user-defined data type that serves as a blueprint or template for creating objects. It defines a set of attributes (data members) and methods (member functions) that represent the properties and behaviors of objects belonging to that class.&lt;/p&gt;&lt;p&gt;Here&#39;s a basic example of defining a class in C++:&lt;/p&gt;&lt;p&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Data members (attributes)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Member functions (methods)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;};&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In this example, we&#39;ve defined a class named Rectangle with data members length and width to represent the dimensions of a rectangle and a member function calculateArea() to calculate its area.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Objects&lt;/h3&gt;&lt;p&gt;Objects are instances of classes. They are created based on the blueprint provided by the class. Each object has its own set of data members, and you can call the member functions on these objects to perform actions or operations associated with the class.&lt;/p&gt;&lt;p&gt;Here&#39;s how you can create objects of the Rectangle class and use&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Create two Rectangle objects&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect1;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect2;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Initialize the attributes of rect1&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect1.length = 5.0;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect1.width = 3.0;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Initialize the attributes of rect2&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect2.length = 7.0;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect2.width = 4.0;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Calculate and display the areas of the rectangles&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect1: &quot; &amp;lt;&amp;lt; rect1.calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect2: &quot; &amp;lt;&amp;lt; rect2.calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;In this example, we create two Rectangle objects, rect1 and rect2, and set their attributes (length and width). We then call the calculateArea() method on each object to calculate and display their areas.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In summary, classes provide a blueprint for creating objects in C++. Objects are instances of classes, and they encapsulate data and behavior into a single unit, making it easier to model real-world entities and create reusable code.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;A C++ Program example to create and use a car class and its objects.&lt;/p&gt;&lt;p&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;pre&gt;&lt;iostream&gt;&lt;b&gt;using namespace std;

class Car {
public:
    string brand;
    string model;
    int year;
};

int main() {
    Car myCar;
    myCar.brand = &quot;Toyota&quot;;
    myCar.model = &quot;Camry&quot;;
    myCar.year = 2022;

    cout &amp;lt;&amp;lt; &quot;Car: &quot; &amp;lt;&amp;lt; myCar.brand &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; myCar.model &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; myCar.year &amp;lt;&amp;lt; endl;
    return 0;
}
&lt;br /&gt;&lt;/b&gt;&lt;/iostream&gt;&lt;/pre&gt;&lt;pre&gt;&lt;iostream&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;iostream&gt;&lt;b&gt;3. Constructors and Destructors&lt;/b&gt;&lt;/iostream&gt;&lt;/h2&gt;&lt;/iostream&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;In C++, constructors and destructors are special member functions in a class that&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;allow you &lt;/b&gt;&lt;b&gt;to initialize and clean up objects of that class, respectively. &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;Let&#39;s explain constructors &lt;/b&gt;&lt;b&gt;and destructors in the context of the Rectangle &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;class, and provide an example &lt;/b&gt;&lt;b&gt;program: &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;
&lt;/b&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Constructors&lt;/b&gt;&lt;/h3&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;
A constructor is a special member function that is automatically called when an &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;object of &lt;/b&gt;&lt;b&gt;a class is created. It is responsible for initializing the object&#39;s &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;data members. &lt;/b&gt;&lt;b&gt;Constructors have the same name as the class and do not have&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;a return type &lt;/b&gt;&lt;b&gt;(not even void). &lt;/b&gt;&lt;b&gt;You can have multiple constructors with &lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;different parameter &lt;/b&gt;&lt;b&gt;lists, allowing you to create &lt;/b&gt;&lt;b&gt;objects in different ways.&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;
Here&#39;s how you can define and use constructors in the Rectangle class:
&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;
using namespace std;

class Rectangle {
public:
    // Parameterized constructor
    Rectangle(double len, double wid) {
        length = len;
        width = wid;
    }

    // Member function to calculate area
    double calculateArea() {
        return length * width;
    }

private:
    double length;
    double width;
};

int main() {
    // Create Rectangle objects using the parameterized constructor
    Rectangle rect1(5.0, 3.0);
    Rectangle rect2(7.0, 4.0);

    // Calculate and display the areas of the rectangles
    cout &amp;lt;&amp;lt; &quot;Area of rect1: &quot; &amp;lt;&amp;lt; rect1.calculateArea() &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; &quot;Area of rect2: &quot; &amp;lt;&amp;lt; rect2.calculateArea() &amp;lt;&amp;lt; endl;

    return 0;
}&lt;/b&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this example, we&#39;ve added a parameterized constructor to the Rectangle class, which takes two arguments (len and wid) and initializes the length and width data members accordingly. When we create rect1 and rect2 objects, the constructor is automatically called with the specified arguments, initializing the objects with the given dimensions.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Destructors&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;A destructor is another special member function in a class, and it is automatically called when an object goes out of scope or is explicitly destroyed. The destructor is responsible for cleaning up any resources acquired by the object.&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Here&#39;s how you can add a destructor to the Rectangle class:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Parameterized constructor&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle(double len, double wid) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length = len;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; width = wid;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Destructor&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; ~Rectangle() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Rectangle object destroyed.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Member function to calculate area&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Create Rectangle objects using the parameterized constructor&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect1(5.0, 3.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect2(7.0, 4.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Calculate and display the areas of the rectangles&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect1: &quot; &amp;lt;&amp;lt; rect1.calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect2: &quot; &amp;lt;&amp;lt; rect2.calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Objects go out of scope, and destructors are called automatically&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In this updated example, we&#39;ve added a destructor to the Rectangle class, which simply prints a message when the object is destroyed. When rect1 and rect2 go out of scope at the end of the main function, their destructors are automatically called to clean up the objects.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;font-weight: bold; text-align: left;&quot;&gt;4. Access Specifiers&lt;/h2&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;Learn about public, private, and protected access specifiers and how they control the visibility of class members.&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Access specifiers in C++ are keywords that control the visibility and accessibility of class members (data members and member functions) from outside the class. There are three main access specifiers in C++:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Public: Members declared as public are accessible from anywhere in the program. They can be accessed by objects of the class and external functions or classes.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Private: Members declared as private are only accessible within the class. They cannot be accessed directly from outside the class.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Protected: Members declared as protected are similar to private members, but they are accessible by derived classes (in the context of inheritance).&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s use the Rectangle class to illustrate access specifiers:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&amp;nbsp; // Public access specifier&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public data members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to set dimensions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void setDimensions(double len, double wid) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length = len;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; width = wid;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to calculate area&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private:&amp;nbsp; // Private access specifier&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Private data member&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; string color;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&amp;nbsp; // Public access specifier again (not recommended in practice)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to set color (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void setColor(string c) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; color = c;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to get color (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; string getColor() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return color;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing public members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.length = 5.0;&amp;nbsp; &amp;nbsp;// Okay&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.width = 3.0;&amp;nbsp; &amp;nbsp; // Okay&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.setDimensions(7.0, 4.0); // Okay&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of the rectangle: &quot; &amp;lt;&amp;lt; rect.calculateArea() &amp;lt;&amp;lt; endl; // Okay&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing private members (not allowed)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // rect.color = &quot;Red&quot;; // Error: &#39;string Rectangle::color&#39; is private&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing public members for color (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.setColor(&quot;Red&quot;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Color of the rectangle: &quot; &amp;lt;&amp;lt; rect.getColor() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In the Rectangle class above:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;length and width are public data members, so they can be accessed directly from outside the class.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;setDimensions and calculateArea are public member functions, so they can be called from outside the class.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;color is a private data member, so it cannot be accessed directly from outside the class. Attempting to do so will result in a compilation error.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;setColor and getColor are public member functions that allow limited access to the private color member for illustration purposes. In practice, you would typically use setter and getter functions like these to control access to private members.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Access specifiers are crucial for encapsulation and data hiding in C++. They help you control which parts of your class are exposed to the external world, ensuring better control and maintainability of your code.&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;5.&amp;nbsp;&lt;/b&gt;&lt;b&gt;Member functions in C++&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Member functions in C++ are functions defined within a class, and they operate on the data members (attributes) of that class. These functions define the behavior or operations that can be performed on objects of the class. Member functions can be categorized as public, private, or protected, depending on their access specifiers.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s continue using the Rectangle class as an example to illustrate member functions:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public data members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to set dimensions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void setDimensions(double len, double wid) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length = len;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; width = wid;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to calculate area&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Private data member&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; string color;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to set color (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void setColor(string c) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; color = c;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to get color (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; string getColor() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return color;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing public data members and member functions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.setDimensions(7.0, 4.0); // Calling a public member function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of the rectangle: &quot; &amp;lt;&amp;lt; rect.calculateArea() &amp;lt;&amp;lt; endl; // Calling a public member function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing private data members via public member functions (just for illustration)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.setColor(&quot;Red&quot;); // Calling a public member function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Color of the rectangle: &quot; &amp;lt;&amp;lt; rect.getColor() &amp;lt;&amp;lt; endl; // Calling a public member function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In the Rectangle class and the main function above:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;setDimensions and calculateArea are public member functions. They are defined within the class and can be accessed and called from outside the class using an object of the class, as shown in the main function.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;setColor and getColor are public member functions used to set and get the color data member. These functions provide controlled access to the private color member, ensuring that it can only be modified or accessed through these functions.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Member functions are essential for encapsulation in object-oriented programming. They allow you to define how objects of a class interact with and manipulate their data. By controlling access to data members through member functions, you can enforce data integrity and maintain the internal state of objects while providing a well-defined interface for users of the class.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;6. Inheritance in C++&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Inheritance is a fundamental concept in object-oriented programming (OOP) that allows you to create a new class (called a derived or child class) by inheriting properties and behaviors from an existing class (called a base or parent class). In C++, you can implement inheritance using the class keyword along with the colon : to specify the base class.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s illustrate inheritance using the Rectangle class as the base class and creating a ColoredRectangle class as the derived class.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Here&#39;s an example program:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Base class: Rectangle&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle(double len, double wid) : length(len), width(wid) {}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Derived class: ColoredRectangle&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class ColoredRectangle : public Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; string color;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Constructor for ColoredRectangle&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; ColoredRectangle(double len, double wid, string c) : Rectangle(len, wid), color(c) {}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Create a ColoredRectangle object&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; ColoredRectangle coloredRect(7.0, 4.0, &quot;Red&quot;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing base class members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of the colored rectangle: &quot; &amp;lt;&amp;lt; coloredRect.calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing derived class member&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Color of the colored rectangle: &quot; &amp;lt;&amp;lt; coloredRect.color &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this example:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;The Rectangle class is defined as the base class. It has data members length and width, along with a constructor to initialize them and a calculateArea function to calculate the area of a rectangle.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;The ColoredRectangle class is defined as the derived class. It inherits the properties of the Rectangle class (i.e., length and width) and adds an additional data member color. It has its constructor that initializes the base class&#39;s members along with its own color member.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;In the main function, we create a ColoredRectangle object, coloredRect, using the derived class constructor. This object inherits the length and width attributes from the base class Rectangle and has its color attribute.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;We can access both the base class&#39;s member function (calculateArea()) and the derived class&#39;s member (color) using the coloredRect object.&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Inheritance allows for code reuse and the creation of specialized classes based on existing ones. It promotes a hierarchical structure, making it easier to model real-world relationships between objects. In this example, ColoredRectangle is a specialized version of a Rectangle with an additional property, demonstrating how inheritance can be used to build upon existing classes.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;7. Polymorphism in C++&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Polymorphism is a fundamental concept in object-oriented programming (OOP) that allows objects of different classes to be treated as objects of a common base class. It enables you to write more flexible and reusable code by allowing different classes to provide their own implementations of common functions.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In C++, polymorphism is primarily achieved through function overriding and virtual functions. Let&#39;s demonstrate polymorphism using the Rectangle class example:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Base class: Shape&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; virtual double calculateArea() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0.0; // Default implementation for the base class&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Derived class: Rectangle&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle : public Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle(double len, double wid) : length(len), width(wid) {}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Overriding the calculateArea() function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() override {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Create a Rectangle object&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect(7.0, 4.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Create a Shape pointer pointing to a Rectangle object&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Shape* shapePtr = &amp;amp;rect;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Calculate the area using polymorphism&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of the shape: &quot; &amp;lt;&amp;lt; shapePtr-&amp;gt;calculateArea() &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;font-weight: bold; text-align: left;&quot;&gt;Types of Polymophism in C++&lt;/h2&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Polymorphism in C++ can be classified into two main types: compile-time (static) polymorphism and runtime (dynamic) polymorphism. These two types of polymorphism are achieved through different mechanisms and are used in different scenarios:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Compile-Time (Static) Polymorphism:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Compile-time polymorphism is also known as static polymorphism because the selection of which function to call is done at compile time, not at runtime. This type of polymorphism is achieved through function overloading and operator overloading.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Function Overloading: As explained earlier, function overloading allows you to define multiple functions with the same name but with different parameter lists. The compiler selects the appropriate function to call based on the arguments provided during the function call.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Operator Overloading: Operator overloading allows you to define custom behaviors for operators, such as +, -, *, /, ==, and more, when applied to objects of user-defined classes. This is determined at compile time based on the operator used and the types of operands.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Example using function overloading:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;int add(int a, int b);&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;double add(double a, double b);&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Example using operator overloading:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;class Complex {&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;public:&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp; Complex operator+(const Complex&amp;amp; other);&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;};&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Runtime (Dynamic) Polymorphism:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Runtime polymorphism is achieved through function overriding and virtual functions. In this type of polymorphism, the selection of which function to call is determined at runtime, based on the actual type of the object being referred to (late binding). Runtime polymorphism is primarily used in scenarios involving inheritance and base and derived classes.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Function Overriding: Function overriding allows a derived class to provide its own implementation of a function that is already defined in the base class. The selection of which function to call is determined based on the type of the object being referred to at runtime. To enable this behavior, you mark the base class function with the virtual keyword and override it in the derived class.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Virtual Functions: A virtual function is a member function in the base class that is declared with the virtual keyword. Virtual functions enable dynamic binding, meaning that the actual function to be called is determined at runtime based on the type of the object being referred to. The derived class can override the virtual function.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Example using function overriding and virtual functions:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;class Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; virtual void draw() const {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Drawing a shape.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Circle : public Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void draw() const override {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Drawing a circle.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In summary, C++ supports both compile-time polymorphism (achieved through function and operator overloading) and runtime polymorphism (achieved through function overriding and virtual functions). These types of polymorphism provide flexibility and extensibility to your programs, allowing you to write more dynamic and expressive code.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Here are separate complete programs that illustrate both compile-time polymorphism and runtime polymorphism using C++:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;Compile-Time (Static) Polymorphism Example:&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Function Overloading for addition&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int add(int a, int b) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return a + b;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;double add(double a, double b) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return a + b;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; int num1 = 5, num2 = 7;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double num3 = 3.5, num4 = 2.1;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Compile-time polymorphism using function overloading&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; int result1 = add(num1, num2);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double result2 = add(num3, num4);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Result 1: &quot; &amp;lt;&amp;lt; result1 &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Result 2: &quot; &amp;lt;&amp;lt; result2 &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this program, we have two add functions that are overloaded based on their parameter types (integers and doubles). The appropriate function to call is determined at compile time based on the argument types provided during the function calls.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Runtime (Dynamic) Polymorphism Example:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Base class: Shape&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; virtual void draw() const {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Drawing a shape.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;// Derived class: Circle&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Circle : public Shape {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void draw() const override {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Drawing a circle.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Creating objects of base and derived classes&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Shape shape;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Circle circle;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Using runtime polymorphism (dynamic binding)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Shape* shapePtr = &amp;amp;circle; // Pointer to a Circle object&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; shapePtr-&amp;gt;draw(); // Calls the draw() function of the Circle class&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In this program, we have a base class Shape with a virtual function draw, and a derived class Circle that overrides the draw function. We create objects of both classes and demonstrate runtime polymorphism by using a pointer to the base class (Shape) that points to an object of the derived class (Circle). The appropriate draw function is determined at runtime based on the type of the object being referred to.&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;8. Encapsulation in C++ Programming&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Encapsulation is one of the four fundamental principles of object-oriented programming (OOP), along with inheritance, polymorphism, and abstraction. It refers to the practice of bundling data (attributes or properties) and the methods (functions or behaviors) that operate on that data into a single unit known as a class. Encapsulation restricts direct access to some of the object&#39;s components and prevents unintended interference, providing better control over the data and the functions that manipulate it.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s use the Rectangle class as an example to demonstrate encapsulation:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private: // Private access specifier for data members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member functions to set and get the dimensions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void setDimensions(double len, double wid) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (len &amp;gt; 0.0 &amp;amp;&amp;amp; wid &amp;gt; 0.0) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length = len;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; width = wid;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Invalid dimensions. Please provide positive values.&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double getLength() const { // Using const member function for read-only access&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double getWidth() const { // Using const member function for read-only access&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() const { // Using const member function for read-only access&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Setting dimensions using the public member function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.setDimensions(7.0, 4.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Accessing dimensions and calculating area using public member functions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Length: &quot; &amp;lt;&amp;lt; rect.getLength() &amp;lt;&amp;lt; &quot; units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Width: &quot; &amp;lt;&amp;lt; rect.getWidth() &amp;lt;&amp;lt; &quot; units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area: &quot; &amp;lt;&amp;lt; rect.calculateArea() &amp;lt;&amp;lt; &quot; square units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Attempting to access private data members directly (not allowed)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // rect.length = 10.0; // Error: &#39;double Rectangle::length&#39; is private&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this example:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;The Rectangle class encapsulates the length and width data members as private members, preventing direct access from outside the class.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Public member functions (setDimensions, getLength, getWidth, and calculateArea) are provided to allow controlled access to the private data members. The setDimensions function ensures that only valid dimensions (positive values) are set.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;In the main function, we use the public member functions to set and retrieve the dimensions and calculate the area of the rectangle. Attempting to access the private data members directly would result in a compilation error.&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;9.&amp;nbsp;&lt;/b&gt;&lt;b&gt;Encapsulation&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Encapsulation helps in maintaining the integrity of the data by preventing unauthorized access and manipulation. It also allows for better code organization and flexibility in changing the internal implementation of the class without affecting the code that uses the class&#39;s public interface.&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Abstraction is one of the core principles of object-oriented programming (OOP). It involves simplifying complex reality by modeling classes based on the essential features and properties while hiding the unnecessary details. In C++, abstraction is achieved by defining a class interface that exposes only relevant information to the outside world while concealing the implementation details.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s use the Rectangle class to demonstrate abstraction:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private: // Private data members&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Constructor to initialize the dimensions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle(double len, double wid) : length(len), width(wid) {}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to calculate area&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() const { // Using const member function for read-only access&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Public member function to display information (abstraction)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; void display() const {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Rectangle Information:&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Length: &quot; &amp;lt;&amp;lt; length &amp;lt;&amp;lt; &quot; units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Width: &quot; &amp;lt;&amp;lt; width &amp;lt;&amp;lt; &quot; units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area: &quot; &amp;lt;&amp;lt; calculateArea() &amp;lt;&amp;lt; &quot; square units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Creating a Rectangle object&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect(7.0, 4.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Using the abstraction provided by the display function&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rect.display();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this example:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;The Rectangle class encapsulates the length and width data members as private members, as shown in the previous example.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;We have added an additional member function named display(). This function is used to abstract the details of displaying the rectangle&#39;s information. It hides the specific implementation of formatting and displaying the data.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In the main function, we create a Rectangle object named rect and then use the display() member function to display the information about the rectangle. The main function does not need to know how the data is displayed or how the area is calculated; it simply uses the abstraction provided by the display() function.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Abstraction simplifies the usage of classes by providing a clear and simplified interface while hiding the complexity of implementation details. It allows you to focus on the essential aspects of an object and its behavior without being concerned about how it achieves its functionality internally. This principle promotes modularity, maintainability, and code reusability.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Operator overloading in C++&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Operator overloading in C++ allows you to define how operators should behave when applied to objects of user-defined classes. You can provide custom implementations for operators such as +, -, *, /, ==, !=, and more. Operator overloading is a powerful feature that makes your classes more intuitive and expressive.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Let&#39;s demonstrate operator overloading using the Rectangle class to overload the + operator for combining rectangles&#39; areas:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;class Rectangle {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;private:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;public:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle(double len, double wid) : length(len), width(wid) {}&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double calculateArea() const {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return length * width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Overloading the + operator to combine areas of two rectangles&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle operator+(const Rectangle&amp;amp; other) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double newLength = length + other.length;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double newWidth = width + other.width;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return Rectangle(newLength, newWidth);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;};&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;int main() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Creating two Rectangle objects&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect1(7.0, 4.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle rect2(5.0, 3.0);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Calculating the individual areas&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double area1 = rect1.calculateArea();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double area2 = rect2.calculateArea();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect1: &quot; &amp;lt;&amp;lt; area1 &amp;lt;&amp;lt; &quot; square units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Area of rect2: &quot; &amp;lt;&amp;lt; area2 &amp;lt;&amp;lt; &quot; square units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Adding the areas of two rectangles using operator overloading&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Rectangle combinedRect = rect1 + rect2;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; // Calculating the combined area&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; double combinedArea = combinedRect.calculateArea();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt; &quot;Combined Area: &quot; &amp;lt;&amp;lt; combinedArea &amp;lt;&amp;lt; &quot; square units&quot; &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;In this example:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;The Rectangle class is defined as before, with private data members length and width.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;We overload the + operator by defining a member function operator+ inside the class. This function takes another Rectangle object as a parameter and returns a new Rectangle object representing the combined area.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;In the main function, we create two Rectangle objects (rect1 and rect2) and calculate their individual areas using the calculateArea() member function.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;We then use operator overloading by adding the rect1 and rect2 objects together using the + operator. This operation combines their areas and returns a new Rectangle object (combinedRect).&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Finally, we calculate and display the combined area.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Operator overloading allows you to use familiar operators with user-defined classes, making your code more intuitive and readable. It&#39;s important to note that you can overload other operators in a similar way to provide custom behavior for your classes.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/1622787808658326216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2023/10/easy-oop-tutorial-in-c-plus-plus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1622787808658326216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1622787808658326216'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2023/10/easy-oop-tutorial-in-c-plus-plus.html' title='Easy OOP Tutorial in C Plus Plus Programming'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8NtCZTMjnHMWAolGQrknLI8EA7XQjLejhTyf90jqzi3I9XG0ztXE4gPKUYwHY28seue6XdT7tVYTO_ta-4jqQyX0Aq05xgmOzb8QWu0_WMeG_-fB_elol5RlCE-S8VJgvdshkQ-ODly7DDWTmZWz8mnhUVyj64C09SN4ZivMKa1T-Y2GBjLIo4hJdNC4r/s72-c/easy-oop-tutorial-in-c-plus-plus-programming.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-8653022075559011004</id><published>2023-09-06T12:14:00.001+05:00</published><updated>2023-09-06T12:21:03.365+05:00</updated><title type='text'>Binary Search Program in C Plus Plus</title><content type='html'>Binary Search Program in C Plus Plus -&amp;nbsp;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What is Binary Search?&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span face=&quot;Söhne, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, Helvetica Neue, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji&quot; style=&quot;color: #374151;&quot;&gt;&lt;span style=&quot;background-color: #f7f7f8; white-space: pre-wrap;&quot;&gt;Binary search is an efficient algorithm used to search for a specific element in a sorted array or list. When the target element is not found, binary search has a well-defined termination condition.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span face=&quot;Söhne, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, Helvetica Neue, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji&quot; style=&quot;color: #374151;&quot;&gt;&lt;span style=&quot;background-color: #f7f7f8; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span face=&quot;Söhne, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, Helvetica Neue, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji&quot; style=&quot;color: #374151;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYMteU1KgQv0MjJBhKWOO4fNw5T-2cwXiBkXFXRm3YRgSd9TNJyca_aPVHPzN0F-Jh4eW-J66jRev4AB5Z2s5QDdxOiVGU26KjjrmGCD4jrD0YoejQN5jnHgehoJWhKVoyhIcVXx01GCAwQa9oE-XkVKQOiIBxBpdKircVutnltiBER_L1-eJ1ZFypIetG/s590/binary-search-program0in-c-plus-plus.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Binary Search Program in C Plus Plus C ++&quot; border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;590&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYMteU1KgQv0MjJBhKWOO4fNw5T-2cwXiBkXFXRm3YRgSd9TNJyca_aPVHPzN0F-Jh4eW-J66jRev4AB5Z2s5QDdxOiVGU26KjjrmGCD4jrD0YoejQN5jnHgehoJWhKVoyhIcVXx01GCAwQa9oE-XkVKQOiIBxBpdKircVutnltiBER_L1-eJ1ZFypIetG/s16000/binary-search-program0in-c-plus-plus.JPG&quot; title=&quot;Binary Search Program in C Plus Plus C ++&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #f7f7f8; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Binary Search Program in C Plus Plus C ++&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;#include&amp;lt;iostream&amp;gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;pre&gt;&lt;b&gt;&lt;iostream&gt;
using namespace std;

// Binary search function
int binarySearch(int arr[], int size, int target) {
    int beg = 0;
    int end = size - 1;

    while (beg &amp;lt;= end) {
        int mid = beg + (end - beg) / 2; // Calculate the middle index

        if (arr[mid] == target) {
            return mid; // Target found, return the index
        } else if (arr[mid] &amp;lt; target) {
            beg = mid + 1; // Target is in the right half
        } else {
            end = mid - 1; // Target is in the left half
        }
    }

    return -1; // Target not found
}

int main() {
    int arr[] = {10, 55, 56, 78, 90, 91, 100, 200};
    int size = sizeof(arr) / sizeof(arr[0]); // Calculate the size of the array
    int target = 56;

    int result = binarySearch(arr, size, target);

    if (result != -1) {
        cout &amp;lt;&amp;lt; &quot;Target &quot; &amp;lt;&amp;lt; target &amp;lt;&amp;lt; &quot; found at index &quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; endl;
    } else {
        cout &amp;lt;&amp;lt; &quot;Target &quot; &amp;lt;&amp;lt; target &amp;lt;&amp;lt; &quot; not found in the array.&quot; &amp;lt;&amp;lt; endl;
    }

    return 0;
}
&lt;br /&gt;&lt;/iostream&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;&lt;iostream&gt;Output:&lt;/iostream&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;&lt;iostream&gt;
&lt;/iostream&gt;&lt;/b&gt;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/8653022075559011004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2023/09/binary-search-program-in-c-plus-plus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/8653022075559011004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/8653022075559011004'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2023/09/binary-search-program-in-c-plus-plus.html' title='Binary Search Program in C Plus Plus'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYMteU1KgQv0MjJBhKWOO4fNw5T-2cwXiBkXFXRm3YRgSd9TNJyca_aPVHPzN0F-Jh4eW-J66jRev4AB5Z2s5QDdxOiVGU26KjjrmGCD4jrD0YoejQN5jnHgehoJWhKVoyhIcVXx01GCAwQa9oE-XkVKQOiIBxBpdKircVutnltiBER_L1-eJ1ZFypIetG/s72-c/binary-search-program0in-c-plus-plus.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-718518119556675301</id><published>2020-06-30T14:12:00.002+05:00</published><updated>2020-06-30T14:12:24.124+05:00</updated><title type='text'>Basic to Advanced C Plus Plus Programs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: Ubuntu, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;Basic C++ Programs – This page contains a Basic C++ Tutorial with Example C++ Programs for Beginners for Learning C++ Programming.&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://easycodebook.com/basic-c-plus-plus-programs/&quot;&gt;https://easycodebook.com/basic-c-plus-plus-programs/&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/718518119556675301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2020/06/basic-to-advanced-c-plus-plus-programs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/718518119556675301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/718518119556675301'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2020/06/basic-to-advanced-c-plus-plus-programs.html' title='Basic to Advanced C Plus Plus Programs'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6605179992083998303</id><published>2019-05-27T07:41:00.002+05:00</published><updated>2020-09-21T20:40:08.463+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="program in C language to print all prime numbers between 1 and a given number n"/><title type='text'>C++ Program Prime series - All Prime numbers 1 to n</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Write a program in C language to print all prime numbers between 1 and a given number n input by user at run time.&lt;/h3&gt;
This C program will display all prime numbers from 1 to a user supplied&amp;nbsp; number n.&lt;br /&gt;
// &lt;b&gt;cprime, prime in c++, prime series in c++, n prime&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// C++ program to input a number n&lt;br /&gt;
//then prints prime number series from 1 to n&lt;br /&gt;
//that is prints all prime between 1 to n&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioaB4Uu6El2p0KxaxHvc_VvW30Wceluqd8cotkB1hppMe8SeGVHw2Yk1FoBn9gI0DPq8k3k9eLF93Fo_bRKTTybHZp-G6WGi3PoYjsPv5GuBA2jXmIJ5t_go4EprArvQJZI1gL3rKZ6gMS/s1600/cprime-numbers-series-from-1-to-N-program-source-code.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;cprime-numbers-series-from-1-to-N-program-source-code&quot; border=&quot;0&quot; data-original-height=&quot;143&quot; data-original-width=&quot;565&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioaB4Uu6El2p0KxaxHvc_VvW30Wceluqd8cotkB1hppMe8SeGVHw2Yk1FoBn9gI0DPq8k3k9eLF93Fo_bRKTTybHZp-G6WGi3PoYjsPv5GuBA2jXmIJ5t_go4EprArvQJZI1gL3rKZ6gMS/s1600/cprime-numbers-series-from-1-to-N-program-source-code.jpg&quot; title=&quot;cprime-numbers-series-from-1-to-N-program-source-code&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;cprime-numbers-series-from-1-to-N-program-source-code&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int checkPrimeNumber(int);&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;bool isPrime;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;int n, num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter the value of n:&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;for(int n = 2; n &amp;lt;= num; n++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// if n is prime then boolean variable isPrime will be true&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;isPrime = checkPrimeNumber(n);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(isPrime == true)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;n&amp;lt;&amp;lt;&quot; &quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp;return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;1022690524&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
// Function that checks whether n is prime or not&lt;br /&gt;
int checkPrimeNumber(int n) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;bool isPrime = true;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;for(int i = 2; i &amp;lt;= n/2; i++) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; if (n%i == 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;isPrime = false;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp;return isPrime;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Output:&lt;br /&gt;
&lt;br /&gt;
//Enter the value of n:50&lt;br /&gt;
//2 3 5 7 11 13 17 19 23 29 31 37 41 43 47&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;1022690524&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6605179992083998303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2019/05/c-program-prime-series-in-c-n-prime.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6605179992083998303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6605179992083998303'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2019/05/c-program-prime-series-in-c-n-prime.html' title='C++ Program Prime series - All Prime numbers 1 to n'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioaB4Uu6El2p0KxaxHvc_VvW30Wceluqd8cotkB1hppMe8SeGVHw2Yk1FoBn9gI0DPq8k3k9eLF93Fo_bRKTTybHZp-G6WGi3PoYjsPv5GuBA2jXmIJ5t_go4EprArvQJZI1gL3rKZ6gMS/s72-c/cprime-numbers-series-from-1-to-N-program-source-code.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-3316939155395099461</id><published>2018-03-24T19:51:00.001+05:00</published><updated>2019-07-15T18:27:05.416+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Input Base"/><category scheme="http://www.blogger.com/atom/ns#" term="Calculate Area"/><category scheme="http://www.blogger.com/atom/ns#" term="Easyway How To Write a Program in C++ for Calculating Area of Triangle When base and height is given"/><category scheme="http://www.blogger.com/atom/ns#" term="Height of Triangle"/><title type='text'>C++ Program To Input Base, Height of Triangle, Calculate Area</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Easyway How To Write a Program in C++ for Calculating Area of Triangle When base and height is given&lt;/h3&gt;
Program Statement: Write a C++ program to input base and height of a triangle and calculates and prints the area of triangle.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoIRQyJk4iVo-fC4ohEVOzuKiRpzsntggHYeEORYjC4Y9ck2vw-vZzY54vXZewEuoarnlP-ppRSD1Vqc2eA94yyoS6Ig-8_jbe2bRLLJPJIV40kpt_rKNlFxsB3iQ3lkNyE8fXrROMUMJY/s1600/input-base-height-triangle-compute-area-easyway-c-plus-plus-program.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Input base and height, compute area of triangle c++ program&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;644&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoIRQyJk4iVo-fC4ohEVOzuKiRpzsntggHYeEORYjC4Y9ck2vw-vZzY54vXZewEuoarnlP-ppRSD1Vqc2eA94yyoS6Ig-8_jbe2bRLLJPJIV40kpt_rKNlFxsB3iQ3lkNyE8fXrROMUMJY/s1600/input-base-height-triangle-compute-area-easyway-c-plus-plus-program.jpg&quot; title=&quot;Input base and height, compute area of triangle c++ program&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Input base and height, compute area of triangle c++ program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Formula for Area of Triangle C++ program when base and height are given&lt;/h3&gt;
&lt;br /&gt;
The formula for area of triangle to be used in this C++ program is as as follows:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;area of triangle = 1 / 2 x base x height&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
How Formula of&amp;nbsp; Area of Triangle is Transformed into C++ Arithmetic Expressions&lt;/h4&gt;
In C++ programming, we write the above formula as following C++ expression.&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
area = 1.0/2.0 * base * height&lt;/h4&gt;
&lt;div&gt;
or we can also use the formula: area = 0.5 * base * height&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Source Code for Modern C++ Compilers / IDEs&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#include&amp;lt;iomanip&amp;gt;  &lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; std;
&lt;span style=&quot;color: #2b91af;&quot;&gt;int&lt;/span&gt; main()
{

   &lt;span style=&quot;color: #2b91af;&quot;&gt;float&lt;/span&gt; area, base, height;
   
    cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter base  = &quot;&lt;/span&gt;;
    cin&amp;gt;&amp;gt;base;
    cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter height  = &quot;&lt;/span&gt;;
    cin&amp;gt;&amp;gt;height;
   
    area = 1.0 / 2.0  * base * height;
 
    cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Area of  Triangle = &quot;&lt;/span&gt;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;area&amp;lt;&amp;lt;endl;
    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; 0;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
C++ Source Code for Calculating Area of Triangle When Base and Height are Given (for Turbo C++ 3.0 compiler / IDE)&lt;/h3&gt;
&lt;div&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;conio.h&amp;gt;&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;iomanip.h&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
void main()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;float area, base, height;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;clrscr();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter base&amp;nbsp; = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;base;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter height&amp;nbsp; = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;height;&lt;/div&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; area = 1.0 / 2.0&amp;nbsp; * base * height;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;1022690524&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Area of&amp;nbsp; Triangle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;area&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; getch();&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Sample Run Output Window: Area of Triangle in C Plus Plus Program&amp;nbsp;&lt;/h3&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcnl1mucgHTl4mqlYIVlmpQ7EhjMLXEk9Qv1CL7CqWdLskLLjS9SIkB_-OL9K4UCaePVLFd3UzsFlRCSat1k73G2ZHrYGGnrz_SFOHu5J7v-cJnqI0eVSFYdK_6xV-9wywS4QmT9RvL6w0/s1600/input-base-height-triangle-compute-area-easyway-c-plus-plus-run.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;224&quot; data-original-width=&quot;435&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcnl1mucgHTl4mqlYIVlmpQ7EhjMLXEk9Qv1CL7CqWdLskLLjS9SIkB_-OL9K4UCaePVLFd3UzsFlRCSat1k73G2ZHrYGGnrz_SFOHu5J7v-cJnqI0eVSFYdK_6xV-9wywS4QmT9RvL6w0/s1600/input-base-height-triangle-compute-area-easyway-c-plus-plus-run.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
How This Program works : C++ Source Code for Calculating Area of Triangle When Base and Height are Given&lt;/h3&gt;
&lt;div&gt;
Here is a detailed C++ program with simplified documentation included as C++ comments, so that the logic of C++ Program Area of Triangle can be understood by readers and other C++ programmers easily:&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp;//include for cin, cout&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;conio.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;//include for clrscr()&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;iomanip.h&amp;gt;&amp;nbsp; //include for setprecision()&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
void main()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;float area, base, height;&amp;nbsp; &amp;nbsp;//declare variables&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;clrscr();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter base&amp;nbsp; = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;base;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //input base&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter height&amp;nbsp; = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;height;&amp;nbsp; &amp;nbsp; &amp;nbsp; //input height&lt;/div&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; area = 1.0 / 2.0&amp;nbsp; * base * height;&amp;nbsp; //compute area&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Area of&amp;nbsp; Triangle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;area&amp;lt;&amp;lt;endl; // show result&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; getch();&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
Enter Base: 5.2&lt;br /&gt;
Enter Height: 10.8&lt;br /&gt;
Area of Triangle = 28.08&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/3316939155395099461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/input-base-height-of-triangle-calculate-area-easyway.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3316939155395099461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3316939155395099461'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/input-base-height-of-triangle-calculate-area-easyway.html' title='C++ Program To Input Base, Height of Triangle, Calculate Area'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoIRQyJk4iVo-fC4ohEVOzuKiRpzsntggHYeEORYjC4Y9ck2vw-vZzY54vXZewEuoarnlP-ppRSD1Vqc2eA94yyoS6Ig-8_jbe2bRLLJPJIV40kpt_rKNlFxsB3iQ3lkNyE8fXrROMUMJY/s72-c/input-base-height-triangle-compute-area-easyway-c-plus-plus-program.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6496256730536500893</id><published>2018-03-24T19:12:00.004+05:00</published><updated>2018-05-17T14:30:31.979+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Program Compute Sum of Cubes of Digits of User Supplied Number"/><title type='text'>C++ Program Compute Sum of Cubes of Digits of User Supplied Number Easyway</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Q: Write a Program in C++ Programming language that&amp;nbsp;inputs an integer number and computes the sum of cubes of digits of&amp;nbsp; this user supplied number at run time.&lt;/h4&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, if given number is 123 then answer will be Sum of cubes of&amp;nbsp; digits = 36&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; because 1&lt;sup&gt;3&lt;/sup&gt;+2&lt;sup&gt;3&lt;/sup&gt;+3&lt;sup&gt;3&lt;/sup&gt;&amp;nbsp;= 1+8+27 = 36.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggVrkd-33PBkPxsQxxlmvQN3LGpmpGmI-yoOBTKxjORCrn_S6ceKXCKOKV7fkVv-92kHg7oitIp0_1O_Z-GE6aT48Ux0lH-HukSkBXRj-6xdVSeuTRSw5pOp03unbD6uyXsMx3I3-tfTCm/s1600/program-easyway-compute-cubes-digits-number-c-plus-plus.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to compute sum of cubes of digits of user supplied number&quot; border=&quot;0&quot; data-original-height=&quot;534&quot; data-original-width=&quot;601&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggVrkd-33PBkPxsQxxlmvQN3LGpmpGmI-yoOBTKxjORCrn_S6ceKXCKOKV7fkVv-92kHg7oitIp0_1O_Z-GE6aT48Ux0lH-HukSkBXRj-6xdVSeuTRSw5pOp03unbD6uyXsMx3I3-tfTCm/s1600/program-easyway-compute-cubes-digits-number-c-plus-plus.jpg&quot; title=&quot;C++ Program to compute sum of cubes of digits of user supplied number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;C++ Program to compute sum of cubes of digits of user supplied number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;C++ Source Code of Sum of cubes of Digits of a given number Program&lt;/h3&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display sum of cubes of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;long num, temp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;int, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to add cubes of its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum = sum&amp;nbsp;+&amp;nbsp; ( r * r * r);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The sum of cubes of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;sum;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMupwsMdOvoaGnu79pcmtbdqxiG2Vc579XE12FpSfsPrI7a4oD28IyP_tXhdbmGViDTMallWqoLOfBu9rZf4DzdIFtIraLKFHGRORW0EIt_ySqV2qwWXSQ4QFLxjFu-pEpu_apRPHSj7mu/s1600/program-compute-sum-cubes-user-supplied-number-output.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Calculate-cubes-of-digits-of-user-given number&quot; border=&quot;0&quot; data-original-height=&quot;284&quot; data-original-width=&quot;707&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMupwsMdOvoaGnu79pcmtbdqxiG2Vc579XE12FpSfsPrI7a4oD28IyP_tXhdbmGViDTMallWqoLOfBu9rZf4DzdIFtIraLKFHGRORW0EIt_ySqV2qwWXSQ4QFLxjFu-pEpu_apRPHSj7mu/s1600/program-compute-sum-cubes-user-supplied-number-output.jpg&quot; title=&quot;Calculate-cubes-of-digits-of-user-given number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Calculate-cubes-of-digits-of-user-given number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;The Working of&amp;nbsp; C++ Code of Add Digits of a given number Program&lt;/h3&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
This program is of reverse number logic.&lt;br /&gt;
&lt;br /&gt;
1. We will divide 123 by 10 and get quotient=12, r = 3&lt;br /&gt;
2. add r*r*r=3*3*3&amp;nbsp; into sum, so sum=27&lt;br /&gt;
&lt;br /&gt;
3. Now put q =12 into dividend number&lt;br /&gt;
4. so divide 12 by 10, quotient=1 and remainder r=2.&lt;br /&gt;
5. Add r*r*r=2*2*2 into sum, so sum will become 27+8&amp;nbsp;=35.&lt;br /&gt;
6. now put q=1 into dividend number&lt;br /&gt;
&lt;br /&gt;
7. Now divide 1 by 10, quotient=0 and r=1.&lt;br /&gt;
8. so add r*r*r=1*1*1 into sum, and sum becomes 35+1= 36&lt;br /&gt;
9. now put quotient=0 into dividend number called temp variable&lt;br /&gt;
10. so that while loop test condition while (temp&amp;gt;0) becomes false and loop terminates.&lt;br /&gt;
&lt;br /&gt;
11. Therefore display the answer sum of cubes of digits of number 123 = 36&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6496256730536500893/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-compute-sum-of-cubes-of-digits-user-supplied-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6496256730536500893'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6496256730536500893'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-compute-sum-of-cubes-of-digits-user-supplied-number.html' title='C++ Program Compute Sum of Cubes of Digits of User Supplied Number Easyway'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggVrkd-33PBkPxsQxxlmvQN3LGpmpGmI-yoOBTKxjORCrn_S6ceKXCKOKV7fkVv-92kHg7oitIp0_1O_Z-GE6aT48Ux0lH-HukSkBXRj-6xdVSeuTRSw5pOp03unbD6uyXsMx3I3-tfTCm/s72-c/program-easyway-compute-cubes-digits-number-c-plus-plus.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-7079802954363599579</id><published>2018-03-24T15:01:00.002+05:00</published><updated>2019-05-28T21:59:31.298+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Program Calculate Sum of Squares of Digits of Given Number"/><title type='text'>C++ Program Calculate Sum of Squares of Digits of Given Number</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Q: Write a C++ Program to input an integer number. Calculate the sum of squares of digits of&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this number.&lt;/h4&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, if given number is 123 then answer will be Sum squares of&amp;nbsp; digits = 14&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; because 1&lt;sup&gt;2&lt;/sup&gt;+2&lt;sup&gt;2&lt;/sup&gt;+3&lt;sup&gt;2&lt;/sup&gt; = 1+4+9 = 14.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSlmMx-Hb1RFcPft6joQ-t8bsm8EzSzmFO8RR_sn8GVfE96pSyWRgNCTxL7RGajGznnPC5RwO0Bbuf4P-w3yihfSEHwqG0MyGwiItI6V8x-hqc_iXaS3bSe6lBQs5jWfCVjjUi3N79ttC/s1600/easyway-calculate-sum-of-squares-of-digits-of-number.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to Calculate sum of squares of digits of given number&quot; border=&quot;0&quot; data-original-height=&quot;407&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSlmMx-Hb1RFcPft6joQ-t8bsm8EzSzmFO8RR_sn8GVfE96pSyWRgNCTxL7RGajGznnPC5RwO0Bbuf4P-w3yihfSEHwqG0MyGwiItI6V8x-hqc_iXaS3bSe6lBQs5jWfCVjjUi3N79ttC/s1600/easyway-calculate-sum-of-squares-of-digits-of-number.jpg&quot; title=&quot;C++ Program to Calculate sum of squares of digits of given number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;C++ Program to Calculate sum of squares of digits of given number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;C++ Code of Sum of Squares of Digits of a given number Program&lt;/h3&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display sum of squares of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to add square of its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum = sum&amp;nbsp;+&amp;nbsp; ( r * r);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The sum of squares of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;sum;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The Working of&amp;nbsp; C++ Code of Add Digits of a given number Program&lt;/h3&gt;
This program is of reverse number logic.&lt;br /&gt;
&lt;br /&gt;
1. We will divide 123 by 10 and get quotient=12, r = 3&lt;br /&gt;
2. add r*r=3*3&amp;nbsp; into sum, so sum=9&lt;br /&gt;
&lt;br /&gt;
3. Now put q =12 into dividend number&lt;br /&gt;
4. so divide 12 by 10, quotient=1 and remainder r=2.&lt;br /&gt;
5. Add r*r=2*2 into sum, so sum will become 9+4 =13.&lt;br /&gt;
6. now put q=1 into dividend number&lt;br /&gt;
&lt;br /&gt;
7. Now divide 1 by 10, quotient=0 and r=1.&lt;br /&gt;
8. so add r*r=1*1 into sum, and sum becomes 13+1= 14&lt;br /&gt;
9. now put quotient=0 into dividend number called temp variable&lt;br /&gt;
10. so that while loop test condition while (temp&amp;gt;0) becomes false and loop terminates.&lt;br /&gt;
&lt;br /&gt;
11. Therefore display the answer sum of squares of digits of number 123 = 14&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjWtGN-M7IXe5cqMTbeI3Luid4KaOqOo2nxQGDx9yuxvpnAG9BfvQLpLl1IV4ebTDqlkBPDNki9x6T35po9EZb7dlEALUtDY2o8XpEDmwzlw82Xb1Ux3hVsk65q9FxNJznUtXc1lGDz4FC/s1600/easyway-calculate-sum-of-squares-of-digits-of-number-output.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to Calculate sum of squares of digits of given number output of execution&quot; border=&quot;0&quot; data-original-height=&quot;332&quot; data-original-width=&quot;719&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjWtGN-M7IXe5cqMTbeI3Luid4KaOqOo2nxQGDx9yuxvpnAG9BfvQLpLl1IV4ebTDqlkBPDNki9x6T35po9EZb7dlEALUtDY2o8XpEDmwzlw82Xb1Ux3hVsk65q9FxNJznUtXc1lGDz4FC/s1600/easyway-calculate-sum-of-squares-of-digits-of-number-output.jpg&quot; title=&quot;C++ Program to Calculate sum of squares of digits of given number sample run&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;C++ Program to Calculate sum of squares of digits of given number execution&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display sum squares of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// include header files&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to add its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// input number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// copy number into temp variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&amp;nbsp; &amp;nbsp; &amp;nbsp; // loop while temp is greater than zero&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&amp;nbsp; &amp;nbsp; &amp;nbsp; // calculate quotient = temp number / 10, if num is 123 then q=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&amp;nbsp; //&amp;nbsp; calculate remainder r = 123 % 10, r = 3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum = sum&amp;nbsp;+ ( r * r );&amp;nbsp; // sum = 0&amp;nbsp;+ 3x3 =0+9&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // so square of last digit 3 of 123 is added in sum&amp;nbsp; variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&amp;nbsp; &amp;nbsp; &amp;nbsp; // set next time dividend&amp;nbsp; &amp;nbsp; &amp;nbsp;temp=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The sum of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;sum; //sum=14&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/7079802954363599579/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-calculate-sum-of-squares-of-digits-of-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7079802954363599579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7079802954363599579'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-calculate-sum-of-squares-of-digits-of-number.html' title='C++ Program Calculate Sum of Squares of Digits of Given Number'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSlmMx-Hb1RFcPft6joQ-t8bsm8EzSzmFO8RR_sn8GVfE96pSyWRgNCTxL7RGajGznnPC5RwO0Bbuf4P-w3yihfSEHwqG0MyGwiItI6V8x-hqc_iXaS3bSe6lBQs5jWfCVjjUi3N79ttC/s72-c/easyway-calculate-sum-of-squares-of-digits-of-number.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-1497106164648333593</id><published>2018-03-24T07:42:00.000+05:00</published><updated>2018-06-18T05:02:45.160+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Calculate Product of Digits of Given Number"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Find Product of Digits of Given Number"/><category scheme="http://www.blogger.com/atom/ns#" term="Program Calculate Product of Digits of Given Number C Plus Plus"/><title type='text'>C++ Program To Find Product of Digits of Given Number </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Q: Input an integer number. Find and show the product / multiplication of digits of given number. That is we have to multiply digits of number.&lt;/h4&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, if given number is 123 then answer will be Product of digits = 6&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; because 1 x 2 x 3 = 6.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdrdaDB7A7jxbajS0LbJCwqKaWs6WiTmWBv6wXTanXcgQAnFDa3rFoxUuu-Cp33zxw9kF_AYWuikQBhTCEKlRv88-zOqGP_pWSWB3njeL_UBfk9E7n0gCNz10KzBDGKzBiXgasDpqAmi0d/s1600/program-product-multiply-digits-of-number-c-plus-plus.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to calculate product of digits of a number&quot; border=&quot;0&quot; data-original-height=&quot;380&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdrdaDB7A7jxbajS0LbJCwqKaWs6WiTmWBv6wXTanXcgQAnFDa3rFoxUuu-Cp33zxw9kF_AYWuikQBhTCEKlRv88-zOqGP_pWSWB3njeL_UBfk9E7n0gCNz10KzBDGKzBiXgasDpqAmi0d/s1600/program-product-multiply-digits-of-number-c-plus-plus.jpg&quot; title=&quot;C++ Program to calculate product of digits of a number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;C++ Program to calculate product of digits of a number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;The Actual C++ Code of &lt;u&gt;C++ Program&amp;nbsp;Product of Digits of a given number&lt;/u&gt;&lt;/h3&gt;
/*&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Program to input a number, then display poduct of its digits.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;int num, temp, product=1, r, q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to multiply its Digits=&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;product = product * r;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp = q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The product of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot; = &quot;&amp;lt;&amp;lt;product;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;getch();&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2nlX6u29G_L6LfiYnx9hrcHCHaSmcwiK8vIaD5cxfsB7OMBQNNCcWD-Jgt7VCCF6FhTYv0dxh8t5YnTwMxmGsxPElS1yEMfzrbLthb3FzRlJ_De_XZUclEXTk6Jc5L1hDdm76kcVQ6wRW/s1600/program-product-multiply-digits-of-number-output.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to calculate product of digits of a number output sample run&quot; border=&quot;0&quot; data-original-height=&quot;398&quot; data-original-width=&quot;604&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2nlX6u29G_L6LfiYnx9hrcHCHaSmcwiK8vIaD5cxfsB7OMBQNNCcWD-Jgt7VCCF6FhTYv0dxh8t5YnTwMxmGsxPElS1yEMfzrbLthb3FzRlJ_De_XZUclEXTk6Jc5L1hDdm76kcVQ6wRW/s1600/program-product-multiply-digits-of-number-output.jpg&quot; title=&quot;C++ Program to calculate product of digits of a number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;C++ Program to calculate product of digits of a number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The Working of&amp;nbsp; C++ Code of product of Digits of a given number Program&lt;/h3&gt;
This program is of reverse number logic.&lt;br /&gt;
&lt;br /&gt;
1. We will divide 123 by 10 and get quotient=12, r = 3&lt;br /&gt;
2. multiply r=3 with product which is one so product=3&lt;br /&gt;
&lt;br /&gt;
3. Now put q =12 into dividend number&lt;br /&gt;
4. so divide 12 by 10, quotient=1 and remainder r=2.&lt;br /&gt;
5. Multiply r=2 with product which is 3 so product = 6.&lt;br /&gt;
6. now put q=1 into dividend number&lt;br /&gt;
&lt;br /&gt;
7. Now divide 1 by 10, quotient=0 and r=1.&lt;br /&gt;
8. so multiply r=1 with product which is 6 therefore product becomes 6 x 1 = 6&lt;br /&gt;
9. now put quotient=0 into dividend number called temp variable&lt;br /&gt;
10. so that while loop test condition while (temp&amp;gt;0) becomes false and loop terminates.&lt;br /&gt;
&lt;br /&gt;
11. Therefore display the answer product of digits of number 123 = 6&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display product of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// include header files&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, product=1, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to multiply its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// input number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// copy number into temp variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&amp;nbsp; &amp;nbsp; &amp;nbsp; // loop while temp is greater than zero&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&amp;nbsp; &amp;nbsp; &amp;nbsp; // calculate quotient = temp number / 10, if num is 123 then q=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&amp;nbsp; //&amp;nbsp; calculate remainder r = 123 % 10, r = 3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;product = produt * r;&amp;nbsp; // product = 1* 3; so last digit 3 of 123 is multiplied,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//product=3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&amp;nbsp; &amp;nbsp; &amp;nbsp; // set next time dividend&amp;nbsp; &amp;nbsp; &amp;nbsp;temp=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The product of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;product;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //product=6&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/1497106164648333593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-calculate-product-of-digits-of-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1497106164648333593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1497106164648333593'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-calculate-product-of-digits-of-number.html' title='C++ Program To Find Product of Digits of Given Number '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdrdaDB7A7jxbajS0LbJCwqKaWs6WiTmWBv6wXTanXcgQAnFDa3rFoxUuu-Cp33zxw9kF_AYWuikQBhTCEKlRv88-zOqGP_pWSWB3njeL_UBfk9E7n0gCNz10KzBDGKzBiXgasDpqAmi0d/s72-c/program-product-multiply-digits-of-number-c-plus-plus.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-1936491426732568640</id><published>2018-03-24T06:44:00.001+05:00</published><updated>2019-07-13T12:32:03.995+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Plus Plus program to find count of digits in a given number"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Count Number of Digits in a Given Number"/><category scheme="http://www.blogger.com/atom/ns#" term="Program Count Number of Digits in a Given Number"/><title type='text'>C++ Program To Count Number of Digits in a Given Number</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Q: Input an integer number. Find and show the COUNT of digits of given number.&lt;/h4&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, if given number is 123 then answer will be Count of digits = 3&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; because 123&amp;nbsp; consists of&amp;nbsp; 3 digits.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhna3VSqYy9vVlVUm3VmkIae63H_oP7qmvEwAOrcL3t__JK1ivsTtLxBvUvkeVQQ_gLFGuFfTk3f3OzkY5toNR9sj9PIRv4vG0bW_0mbAeyUZowgUMJKoCbY1x61wswAt9tEtYURE-OgvJB/s1600/program-count-number-of-digits-easyway-c-plus-plus.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to count number of digits in a given number&quot; border=&quot;0&quot; data-original-height=&quot;385&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhna3VSqYy9vVlVUm3VmkIae63H_oP7qmvEwAOrcL3t__JK1ivsTtLxBvUvkeVQQ_gLFGuFfTk3f3OzkY5toNR9sj9PIRv4vG0bW_0mbAeyUZowgUMJKoCbY1x61wswAt9tEtYURE-OgvJB/s1600/program-count-number-of-digits-easyway-c-plus-plus.jpg&quot; title=&quot;C++ Program to count number of digits in a given number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;C++ Program to count number of digits in a given number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;The Actual C++ Code of Add Digits of a given number Program&lt;/h3&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display count of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c)&amp;nbsp;&lt;span style=&quot;color: #38761d;&quot;&gt;Www.EasyCppProgramming.Blogspot.Com for Easyway C++ Programs&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: magenta;&quot;&gt;www.ComputerGap.com&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://www.computergap.com/&quot;&gt;for perfect computer study notes&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;int num, temp, count=0, r, q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to Count its Digits=&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;count++;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp = q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The Count of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;count;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;getch();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The Working of&amp;nbsp; C++ Code of count Digits of a given number Program&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Each and Every Statement Explained&lt;/h3&gt;
This program is of reverse number logic.&lt;br /&gt;
&lt;br /&gt;
1. We will divide 123 by 10 and get quotient=12, r = 3&lt;br /&gt;
2. increment count by 1 so count =1&lt;br /&gt;
&lt;br /&gt;
3. Now put q =12 into dividend number&lt;br /&gt;
4. so divide 12 by 10, quotient=1 and remainder r=2.&lt;br /&gt;
5. increment count by 1, so count =2&lt;br /&gt;
6. now put q=1 into dividend number&lt;br /&gt;
&lt;br /&gt;
7. Now divide 1 by 10, quotient=0 and r=1.&lt;br /&gt;
8. increment to count by 1 so count=3&lt;br /&gt;
9. now put quotient=0 into dividend number called temp variable&lt;br /&gt;
10. so that while loop test condition while (temp&amp;gt;0) becomes false and loop terminates.&lt;br /&gt;
&lt;br /&gt;
11. Therefore display the answer count of digits of number 123 = 3&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc1TJmUJWD_QjV2urFEkkQ8xsAEmotw-Ev_TAZVltgvdCldATd1O3izrSPMoqZT3VPicUD7CjosTlr47see6-rWo3j-k-O1U_wvi2T4sNQJ44z3e9V5ULU-5zQYST-XASNXrbdDFZmv4Lm/s1600/program-count-number-of-digits-easyway-c-plus-plus-execute.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to count number of digits in a given number sample run output&quot; border=&quot;0&quot; data-original-height=&quot;396&quot; data-original-width=&quot;599&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc1TJmUJWD_QjV2urFEkkQ8xsAEmotw-Ev_TAZVltgvdCldATd1O3izrSPMoqZT3VPicUD7CjosTlr47see6-rWo3j-k-O1U_wvi2T4sNQJ44z3e9V5ULU-5zQYST-XASNXrbdDFZmv4Lm/s1600/program-count-number-of-digits-easyway-c-plus-plus-execute.jpg&quot; title=&quot;C++ Program to count number of digits in a given number sample run output&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;C++ Program to count number of digits in a given number sample run output&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display count of its digits. with comments /documentation&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// include header files&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to count its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// input number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// copy number into temp variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&amp;nbsp; &amp;nbsp; &amp;nbsp; // loop while temp is greater than zero&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&amp;nbsp; &amp;nbsp; &amp;nbsp; // calculate quotient = temp number / 10, if num is 123 then q=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;count++&amp;nbsp;;&amp;nbsp; // starting from 0, increment to count = 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&amp;nbsp; &amp;nbsp; &amp;nbsp; // set next time dividend&amp;nbsp; &amp;nbsp; &amp;nbsp;temp=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The Count of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;count;&amp;nbsp; &amp;nbsp; &amp;nbsp;//count=3&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/1936491426732568640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-count-number-of-digits-given-number-c-plus-plus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1936491426732568640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1936491426732568640'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-count-number-of-digits-given-number-c-plus-plus.html' title='C++ Program To Count Number of Digits in a Given Number'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhna3VSqYy9vVlVUm3VmkIae63H_oP7qmvEwAOrcL3t__JK1ivsTtLxBvUvkeVQQ_gLFGuFfTk3f3OzkY5toNR9sj9PIRv4vG0bW_0mbAeyUZowgUMJKoCbY1x61wswAt9tEtYURE-OgvJB/s72-c/program-count-number-of-digits-easyway-c-plus-plus.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-2225468900185599258</id><published>2018-03-24T00:02:00.002+05:00</published><updated>2018-05-19T23:23:53.577+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Find Sum of Digits of Given Number"/><category scheme="http://www.blogger.com/atom/ns#" term="Program Find Sum of Digits of Given Number"/><category scheme="http://www.blogger.com/atom/ns#" term="Write c++ program to add digits of a number"/><title type='text'>C++ Program To Find Sum of Digits of Given Number</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Q: Input an integer number. Find and show the sum of digits of given number.&lt;/h4&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, if given number is 123 then answer will be Sum of digits = 6&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; because 1+2+3 = 6.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxMxKILgAXXPW0HqjA89rdYTJId_jlBtruw1qDUozEjX0x01wawAN9vaDcliWdRKaGwLJ_uXNgXi2PS_vgAwxVVqdUJxxjGQf-aPptS3Tsbfh19jyKLhNtGzbXkEXZC5qNhndqTAlLZuzw/s1600/c_plus_plus_program_sum_of_digits_of_number.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to find sum of digits of a number&quot; border=&quot;0&quot; data-original-height=&quot;458&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxMxKILgAXXPW0HqjA89rdYTJId_jlBtruw1qDUozEjX0x01wawAN9vaDcliWdRKaGwLJ_uXNgXi2PS_vgAwxVVqdUJxxjGQf-aPptS3Tsbfh19jyKLhNtGzbXkEXZC5qNhndqTAlLZuzw/s1600/c_plus_plus_program_sum_of_digits_of_number.jpg&quot; title=&quot;C++ Program to Input Number Add its digits C++ Program&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Input Number Add its digits C++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The Actual C++ Code of Add Digits of a given number Program&lt;/h3&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display sum of its digits.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to add its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum = sum&amp;nbsp;+ r;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The sum of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;sum;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjk2_MzVl8_hUanKP66gLhzPreyxmOXLPCuKxxiHx2qJugUHrIkmadAO8wTLnqMpfTg34N8QHYn22UAMztH2XTdLjTS2-os8XUoDyQ2KU7yNLeeqCyidkMBoCBiHGo13oI-TXiQUGPovjj/s1600/program_sum_of_digits_of_number_output_run.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Write C++ Program to find sum of digits of given number&quot; border=&quot;0&quot; data-original-height=&quot;251&quot; data-original-width=&quot;602&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjk2_MzVl8_hUanKP66gLhzPreyxmOXLPCuKxxiHx2qJugUHrIkmadAO8wTLnqMpfTg34N8QHYn22UAMztH2XTdLjTS2-os8XUoDyQ2KU7yNLeeqCyidkMBoCBiHGo13oI-TXiQUGPovjj/s1600/program_sum_of_digits_of_number_output_run.jpg&quot; title=&quot;Write C++ Program to find sum of digits of given number&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Write C++&amp;nbsp;Program to find sum of digits of given number&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The Working of&amp;nbsp; C++ Code of Add Digits of a given number Program&lt;/h3&gt;
This program is of reverse number logic.&lt;br /&gt;
&lt;br /&gt;
1. We will divide 123 by 10 and get quotient=12, r = 3&lt;br /&gt;
2. add r=3 into sum, so sum=3&lt;br /&gt;
&lt;br /&gt;
3. Now put q =12 into dividend number&lt;br /&gt;
4. so divide 12 by 10, quotient=1 and remainder r=2.&lt;br /&gt;
5. Add r=2 into sum, so sum will become 5.&lt;br /&gt;
6. now put q=1 into dividend number&lt;br /&gt;
&lt;br /&gt;
7. Now divide 1 by 10, quotient=0 and r=1.&lt;br /&gt;
8. so add r=1 into sum, and sum becomes 6&lt;br /&gt;
9. now put quotient=0 into dividend number called temp variable&lt;br /&gt;
10. so that while loop test condition while (temp&amp;gt;0) becomes false and loop terminates.&lt;br /&gt;
&lt;br /&gt;
11. Therefore display the answer sum of digits of number 123 = 6&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Program to input a number, then display sum of its digits.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// include header files&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, sum=0, r, q;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;clrscr();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter a number to add its Digits=&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// input number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;temp = num;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// copy number into temp variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( temp&amp;gt;0 )&amp;nbsp; &amp;nbsp; &amp;nbsp; // loop while temp is greater than zero&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = temp/10;&amp;nbsp; &amp;nbsp; &amp;nbsp; // calculate quotient = temp number / 10, if num is 123 then q=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r = temp % 10;&amp;nbsp; //&amp;nbsp; calculate remainder r = 123 % 10, r = 3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum = sum&amp;nbsp;+ r;&amp;nbsp; // sum = 0&amp;nbsp;+ 3; so last digit 3 of 123 is added in sum variable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = q;&amp;nbsp; &amp;nbsp; &amp;nbsp; // set next time dividend&amp;nbsp; &amp;nbsp; &amp;nbsp;temp=12&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;\n The sum of digits of given number &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot;&amp;nbsp; =&amp;nbsp; &quot;&amp;lt;&amp;lt;sum; //sum=6&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/2225468900185599258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-find-sum-of-digits-of-given-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/2225468900185599258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/2225468900185599258'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-find-sum-of-digits-of-given-number.html' title='C++ Program To Find Sum of Digits of Given Number'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxMxKILgAXXPW0HqjA89rdYTJId_jlBtruw1qDUozEjX0x01wawAN9vaDcliWdRKaGwLJ_uXNgXi2PS_vgAwxVVqdUJxxjGQf-aPptS3Tsbfh19jyKLhNtGzbXkEXZC5qNhndqTAlLZuzw/s72-c/c_plus_plus_program_sum_of_digits_of_number.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-3020353576736763607</id><published>2018-03-23T11:26:00.000+05:00</published><updated>2019-07-13T12:39:02.438+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Area and Circumference of Circle Program in C Plus Plus"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program To Calculate Area and Circumference of Circle in C Plus Plus Program"/><title type='text'>C++ Program To Calculate Area and Circumference of Circle in C Plus Plus Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Easyway How To Write a Program in C++ for Calculating Area and Circumference of Circle&lt;/h3&gt;
Program Statement: &lt;u&gt;&lt;b&gt;Write a C++ program to input radius of a circle and calculates and prints the area and circumference&lt;/b&gt;&lt;/u&gt; of the given circle.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidhI0V47wBGX2yn_Qpd5dNPqg9RaI46bPwLoV_cLrpdL8U_ulViCqD_PfdQOgvQr_oYVQeqlgxYlmknxnmUFGpbqbVbGwcQE2y4Ig5H_rVcXIh47vVwwOjjnWCKqkQzjbzGD805cieNhCm/s1600/calculate_area_circumference_circle_c_plus_plus_program.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Calculate area and circumference of circle in C++ Program Easyway&quot; border=&quot;0&quot; data-original-height=&quot;460&quot; data-original-width=&quot;798&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidhI0V47wBGX2yn_Qpd5dNPqg9RaI46bPwLoV_cLrpdL8U_ulViCqD_PfdQOgvQr_oYVQeqlgxYlmknxnmUFGpbqbVbGwcQE2y4Ig5H_rVcXIh47vVwwOjjnWCKqkQzjbzGD805cieNhCm/s1600/calculate_area_circumference_circle_c_plus_plus_program.jpg&quot; title=&quot;Calculate area and circumference of circle in C++ Program Easyway&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Calculate area and circumference of circle in C++ Program Easyway&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
What are the Formulas Used in C++ Program for Area and Circumference of Circle?&lt;/h3&gt;
To write this program, first of all we have to find the accurate formulas for area and circumference of circle.&lt;br /&gt;
These are as follows:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;area of circle =&amp;nbsp;Π R &lt;sup&gt;2&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;circumference of circle =&amp;nbsp; 2 Π R&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
How Formulas of Circle are Transformed into C++ Arithmetic Expressions&lt;/h4&gt;
In C++ programming, we write the above formulas as follows&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;area = 3.14 * radius * radius&lt;/li&gt;
&lt;li&gt;circum = 2 * 3.14 * radius&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Note: 3.14 is the vale of constant PI&amp;nbsp; shown with symbol Π&lt;br /&gt;
&lt;br /&gt;
A Better Programming Approach is to Use Symbolic Constants instead of hard coding numbers directly in C++ programs.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
How To Define a Constant PI in C++ (C++ Program&amp;nbsp;&lt;/h4&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
for Calculating Area and Circumference of&amp;nbsp; Circle&lt;/h3&gt;
There are two ways:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Using #define Pre processor Directive:&amp;nbsp; &amp;nbsp; &amp;nbsp;#define PI&amp;nbsp; 3.14&lt;/li&gt;
&lt;li&gt;Using const Qualifier :&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const float PI = 3.14;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
C++ Source Code for Calculating Area and Circumference of&amp;nbsp; Circle&lt;/h3&gt;
&lt;div&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;conio.h&amp;gt;&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;iomanip.h&amp;gt;&lt;/div&gt;
&lt;div&gt;
#define PI 3.14&lt;/div&gt;
&lt;div&gt;
void main()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;float radius, area, circum;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;clrscr();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter radius of circle = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;radius;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; area = PI * radius * radius;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; circum = 2 * PI * radius;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Area of&amp;nbsp; circle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;area&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Circumference of circle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;circum;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; getch();&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
How This Program Works for Calculating Area and Circumference of&amp;nbsp; Circle&lt;/h3&gt;
&lt;div&gt;
&lt;div&gt;
#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; // include header file for cin, cout&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;conio.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;// include header file for&amp;nbsp; clrscr()&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
#include&amp;lt;iomanip.h&amp;gt;&amp;nbsp; // include header file for setprecision()&lt;/div&gt;
&lt;div&gt;
#define PI 3.14&amp;nbsp; &amp;nbsp;// define constant PI&lt;/div&gt;
&lt;div&gt;
void main()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;float radius, area, circum;&amp;nbsp; &amp;nbsp;declare variables&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;clrscr();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter radius of circle = &quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;radius;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//input radius&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; area = PI * radius * radius;&amp;nbsp; &amp;nbsp;// calculate area&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; circum = 2 * PI * radius;&amp;nbsp; &amp;nbsp;// calculate circumference&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;// used setprecision(2) to show value of area upto two decimal places&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Area of&amp;nbsp; circle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;area&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;// used setprecision(2) to show value of circumference upto two decimal places&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Circumference of circle = &quot;&amp;lt;&amp;lt;setprecision(2)&amp;lt;&amp;lt;circum;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; getch();&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/3020353576736763607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/calculate-area-circumference-circle-c-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3020353576736763607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3020353576736763607'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/calculate-area-circumference-circle-c-program.html' title='C++ Program To Calculate Area and Circumference of Circle in C Plus Plus Program'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidhI0V47wBGX2yn_Qpd5dNPqg9RaI46bPwLoV_cLrpdL8U_ulViCqD_PfdQOgvQr_oYVQeqlgxYlmknxnmUFGpbqbVbGwcQE2y4Ig5H_rVcXIh47vVwwOjjnWCKqkQzjbzGD805cieNhCm/s72-c/calculate_area_circumference_circle_c_plus_plus_program.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6930888778876232242</id><published>2018-03-23T08:41:00.003+05:00</published><updated>2019-07-15T21:28:15.538+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program to Calculate Bonus on Salary Grade Wise"/><category scheme="http://www.blogger.com/atom/ns#" term="Calculate Bonus Salary C Plus Plus Program"/><category scheme="http://www.blogger.com/atom/ns#" term="Write C++ Program To Calculate Bonus on Salary Grade Wise"/><title type='text'>C++ Program to Calculate Bonus on Salary Grade Wise</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Q:&amp;nbsp;Write a &lt;b&gt;&lt;u&gt;C++ Program To Calculate Bonus on Salary Grade Wise&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Program Statement: Write a C++ Program to input &lt;b&gt;salary and grade&lt;/b&gt;. it applies a &lt;b&gt;60% bonus to employees of grade 17 or above&lt;/b&gt;. It adds a &lt;u&gt;30% bonus for all employees of grade less than 17.&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieFQnj2RIstIuD015NnIt-OjJ0yDUbNP2p_Iw9UlPnT0Cqcdj40hrXeifmnHLUpgYqk_BOSKF_uN_dR2lDSiHq_gjNmm9sfHcpCmB8E89XhIupsC16JUXcVw8SfkTh-poxiuDoHVY-gQrR/s1600/salary_bonus_c_plus_plus_program.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program to Calculate Bonus on Salary Grade Wise&quot; border=&quot;0&quot; data-original-height=&quot;481&quot; data-original-width=&quot;627&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieFQnj2RIstIuD015NnIt-OjJ0yDUbNP2p_Iw9UlPnT0Cqcdj40hrXeifmnHLUpgYqk_BOSKF_uN_dR2lDSiHq_gjNmm9sfHcpCmB8E89XhIupsC16JUXcVw8SfkTh-poxiuDoHVY-gQrR/s1600/salary_bonus_c_plus_plus_program.jpg&quot; title=&quot;C++ Program to Calculate Bonus on Salary Grade Wise&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Salary Bonus C|++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Source code of Salary Program for Dev C++ and Modern C++ Compilers / IDEs&lt;/h3&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; std;

&lt;span style=&quot;color: #2b91af;&quot;&gt;int&lt;/span&gt; main()
{
 &lt;span style=&quot;color: #2b91af;&quot;&gt;float&lt;/span&gt; salary,bonus;
 &lt;span style=&quot;color: #2b91af;&quot;&gt;int&lt;/span&gt; grade;
 
 cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter salary of Employee=&quot;&lt;/span&gt;;
 cin&amp;gt;&amp;gt;salary;
 cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter grade=&quot;&lt;/span&gt;;
 cin&amp;gt;&amp;gt;grade;

 &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(grade&amp;gt;=17)
   bonus = salary * 60.0/100.0;
   &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;
   bonus = salary * 30.0/100.0;
 salary = salary + bonus;
 cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;The Total salary of Employee = &quot;&lt;/span&gt;&amp;lt;&amp;lt;salary;

 &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; 0; 
 }
&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Sample output of Salary Grade Bonus Program&lt;/h2&gt;
&lt;div&gt;
&lt;div&gt;
Enter salary of Employee=10000&lt;/div&gt;
&lt;div&gt;
Enter grade=17&lt;/div&gt;
&lt;div&gt;
The Total salary of Employee = 16000&lt;/div&gt;
&lt;div&gt;
--------------------------------&lt;/div&gt;
&lt;div&gt;
Process exited after 26.75 seconds with return value 0&lt;/div&gt;
&lt;div&gt;
Press any key to continue . . .&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
C++&amp;nbsp;Source Code of&amp;nbsp; Program To Calculate Bonus on Salary for Turbo C++ 3.0 IDE / Compiler&lt;/h2&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;iostream.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;conio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;void main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;float salary,bonus;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;int grade;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;clrscr();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter salary of Employee=&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cin&amp;gt;&amp;gt;salary;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter grade=&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cin&amp;gt;&amp;gt;grade;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;if(grade&amp;gt;=17)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;bonus = salary * 60.0/100.0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;bonus = salary * 30.0/100.0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;salary = salary + bonus;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;The Total salary of Employee = &quot;&amp;lt;&amp;lt;salary;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; getch();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Output of Sample Run: Salary Bonus C ++ Program&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1CF1P20Ul7XuPo4mYFkBnatqJuWeU9cS4fmcKizZyeluXdZ-wDDfOhtq9T2Igz8AblF-3fIAkWoljNs89AkTeIkWIjma3LnA96jXg7l6tykQ-UxkcYn4t9KU_zPsyd1PCLATWS9PNsnWI/s1600/calculate_salary_bonus_employee_c_plus_plus_program.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Calculate Salary with Bonus according to Grade C++ Program&quot; border=&quot;0&quot; data-original-height=&quot;212&quot; data-original-width=&quot;517&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1CF1P20Ul7XuPo4mYFkBnatqJuWeU9cS4fmcKizZyeluXdZ-wDDfOhtq9T2Igz8AblF-3fIAkWoljNs89AkTeIkWIjma3LnA96jXg7l6tykQ-UxkcYn4t9KU_zPsyd1PCLATWS9PNsnWI/s1600/calculate_salary_bonus_employee_c_plus_plus_program.jpg&quot; title=&quot;Calculate Salary with Bonus according to Grade C++ Program&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Calculate Salary with Bonus according to Grade C++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
How Salary Bonus C++ Program Works: Logic&lt;/h2&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;iostream.h&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //include header files&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;conio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;void main()&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;float salary,bonus;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;int grade;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;clrscr();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter salary of Employee=&quot;;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cin&amp;gt;&amp;gt;salary;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Enter salary&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;Enter grade=&quot;;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cin&amp;gt;&amp;gt;grade;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// input grade&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;// check if grade greater than or equal to 17&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;if(grade&amp;gt;=17)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;bonus = salary * 60.0/100.0;&amp;nbsp; &amp;nbsp; //&amp;nbsp; calculate 60% bonus&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;bonus = salary * 30.0/100.0; // calculate 30% bonus&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;salary = salary + bonus;&amp;nbsp; &amp;nbsp; &amp;nbsp;// add bonus to salary&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;// print salary&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;cout&amp;lt;&amp;lt;&quot;The Total salary of Employee = &quot;&amp;lt;&amp;lt;salary;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;//for staying output window until the user presses a key&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; getch();&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6930888778876232242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/calculate-bonus-salary-program-c-plus-plus.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6930888778876232242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6930888778876232242'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/calculate-bonus-salary-program-c-plus-plus.html' title='C++ Program to Calculate Bonus on Salary Grade Wise'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieFQnj2RIstIuD015NnIt-OjJ0yDUbNP2p_Iw9UlPnT0Cqcdj40hrXeifmnHLUpgYqk_BOSKF_uN_dR2lDSiHq_gjNmm9sfHcpCmB8E89XhIupsC16JUXcVw8SfkTh-poxiuDoHVY-gQrR/s72-c/salary_bonus_c_plus_plus_program.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-1736421389489640260</id><published>2018-03-22T05:38:00.002+05:00</published><updated>2019-07-15T20:50:12.314+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program Area of Triangle When Three Sides Given"/><category scheme="http://www.blogger.com/atom/ns#" term="easyway c++ program triangle area formula"/><category scheme="http://www.blogger.com/atom/ns#" term="Program Area of Triangle Algorithm Flowchart"/><title type='text'>Program Area of Triangle Algorithm Flowchart</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Q: Write a C++ Program to input three sides of a triangle. The &lt;u&gt;&lt;b&gt;program then calculates the Area of triangle by the formula&amp;nbsp;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjt7Gp4n8zhyphenhyphen8k1ZMQl4ZfOuSePU6EnEv-cwgpuJZQuQmFvM0zp80AwZmQpX42Sbklia9LS4vFSXAqKKOCcv7hv-o9RaGeOBOoOJ126NydvHyQR42HYynx0a6lVPMymBV0hIbfHbJ1Zprn/s1600/formula_area_of_triangle_3_sides.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Formula of area of triangle when 3 sides given&quot; border=&quot;0&quot; data-original-height=&quot;50&quot; data-original-width=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjt7Gp4n8zhyphenhyphen8k1ZMQl4ZfOuSePU6EnEv-cwgpuJZQuQmFvM0zp80AwZmQpX42Sbklia9LS4vFSXAqKKOCcv7hv-o9RaGeOBOoOJ126NydvHyQR42HYynx0a6lVPMymBV0hIbfHbJ1Zprn/s1600/formula_area_of_triangle_3_sides.jpg&quot; title=&quot;Formula of area of triangle when 3 sides given&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Formula of area of triangle when 3 sides given&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Where s = ( a+b+c ) / 2&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Write Down Algorithm of C++&amp;nbsp;Program Area of Triangle&lt;/h2&gt;
&lt;div&gt;
1. Start&lt;/div&gt;
&lt;div&gt;
2. Input a,b,c&lt;/div&gt;
&lt;div&gt;
3. Calculate s = (a&amp;nbsp;+ b&amp;nbsp;+ c ) / 2&lt;/div&gt;
&lt;div&gt;
4. Calculate area = sqrt( s*(s-a)*(s-b)*(s-c))&lt;/div&gt;
&lt;div&gt;
5. print &quot;Area of Triangle=&quot;, area&lt;/div&gt;
&lt;div&gt;
6. End&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Develop Flowchart of C++&amp;nbsp;Program Area of Triangle&lt;/h3&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQqUv9hBWryWJxvA40Q5YWj6PFt7pgieIsyVyIzvjUDYL2JLmwTxho-UzfPBWQV360gtaX1RbwkKx5bU-kSGw6ShwmKwA7dmqBzZl7NTagsTpHRSpTF258Z1kMxylnlrZh9YIj10UbPPWi/s1600/develop_flowchart_c_plus_plus_program_area_of_triangle.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C++ Program develop flowchart c plus plus program area of triangle&quot; border=&quot;0&quot; data-original-height=&quot;697&quot; data-original-width=&quot;379&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQqUv9hBWryWJxvA40Q5YWj6PFt7pgieIsyVyIzvjUDYL2JLmwTxho-UzfPBWQV360gtaX1RbwkKx5bU-kSGw6ShwmKwA7dmqBzZl7NTagsTpHRSpTF258Z1kMxylnlrZh9YIj10UbPPWi/s1600/develop_flowchart_c_plus_plus_program_area_of_triangle.jpg&quot; title=&quot;C++ Program develop flowchart c plus plus program area of triangle&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;develop flowchart c plus plus program area of triangle&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
Generally we prepare a flowchart and algorithm which is independent of&amp;nbsp; any programming language so here is a better flowchart version for &lt;b&gt;&lt;u&gt;C++ Program Area of Triangle&lt;/u&gt;&lt;/b&gt;&amp;nbsp;with mathematical formula instead of C++ arithmetic expressions.&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Flowchart for C++ Program How To Calculate Area of triangle when 3 side are input&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiayxsrQmQs7mAqsQxuktUvFIITqUwNnW62cfOX4-n_q0v831IxHMl7mdSscUYLD0NTpWXgpAj2Nc9IbF04E21wJBS3HgH9FsKzsWdmrIod027bBsDRrcdZFItYDpZ6OLHf5OoBiHCrx6Kr/s1600/develop_flowchart_c_plus_plus_program_area_of_triangle_programming_language_independent_.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;develop flowchart c plus plus program area of triangle programming language independent&quot; border=&quot;0&quot; data-original-height=&quot;692&quot; data-original-width=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiayxsrQmQs7mAqsQxuktUvFIITqUwNnW62cfOX4-n_q0v831IxHMl7mdSscUYLD0NTpWXgpAj2Nc9IbF04E21wJBS3HgH9FsKzsWdmrIod027bBsDRrcdZFItYDpZ6OLHf5OoBiHCrx6Kr/s1600/develop_flowchart_c_plus_plus_program_area_of_triangle_programming_language_independent_.jpg&quot; title=&quot;develop flowchart c plus plus program area of triangle programming language independent&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;develop flowchart c plus plus program area of triangle programming language independent&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Source code for modern C++ IDEs /Compilers ( Used Dev C++ )&lt;/h3&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#include&amp;lt;math.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; std;
&lt;span style=&quot;color: #2b91af;&quot;&gt;int&lt;/span&gt; main( )
{
&lt;span style=&quot;color: #2b91af;&quot;&gt;float&lt;/span&gt; a,b,c,s,area;

cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter side A of triangle = &quot;&lt;/span&gt;;
cin&amp;gt;&amp;gt;a;
cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter side B of triangle = &quot;&lt;/span&gt;;
cin&amp;gt;&amp;gt;b;
cout&amp;lt;&amp;lt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Enter side C of triangle = &quot;&lt;/span&gt;;
cin&amp;gt;&amp;gt;c;

s = (a + b + c ) / 2;

area = sqrt ( s * (s - a ) * (s - b ) * (s - c ) ) ;

cout&amp;lt;&amp;lt; &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Area of Triangle = &quot;&lt;/span&gt;&amp;lt;&amp;lt;area;
&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; 0;

}
&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Output of the sample run:&lt;/h3&gt;
&lt;div&gt;
&lt;div&gt;
Enter side A of triangle = 5&lt;/div&gt;
&lt;div&gt;
Enter side B of triangle = 5&lt;/div&gt;
&lt;div&gt;
Enter side C of triangle = 5&lt;/div&gt;
&lt;div&gt;
Area of Triangle = 10.8253&lt;/div&gt;
&lt;div&gt;
--------------------------------&lt;/div&gt;
&lt;div&gt;
Process exited after 4.697 seconds with return value 0&lt;/div&gt;
&lt;div&gt;
Press any key to continue . . .&lt;/div&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Write Down Source Code of C++&amp;nbsp;Program Area of Triangle for Turbo C++ 3.0 Compiler / IDE&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;#include&amp;lt;iostream.h&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;#include&amp;lt;conio.h&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#include&amp;lt;math.h&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;void main( )&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;{&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;float a,b,c,s,area;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;clrscr();&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;cout&amp;lt;&amp;lt;&quot;Enter side A of triangle = &quot;;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;cin&amp;gt;&amp;gt;a;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b&gt;cout&amp;lt;&amp;lt;&quot;Enter side B of triangle = &quot;;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;cin&amp;gt;&amp;gt;b;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b&gt;cout&amp;lt;&amp;lt;&quot;Enter side C of triangle = &quot;;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;cin&amp;gt;&amp;gt;c;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;s = (a&amp;nbsp;+ b&amp;nbsp;+ c ) / 2;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;area = sqrt ( s * (s - a ) * (s - b ) * (s - c ) ) ;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;cout&amp;lt;&amp;lt; &quot;Area of Triangle = &quot;&amp;lt;&amp;lt;area;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;getch();&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/1736421389489640260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-area-of-triangle-algorithm-flowchartcplusplus.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1736421389489640260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1736421389489640260'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-area-of-triangle-algorithm-flowchartcplusplus.html' title='Program Area of Triangle Algorithm Flowchart'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjt7Gp4n8zhyphenhyphen8k1ZMQl4ZfOuSePU6EnEv-cwgpuJZQuQmFvM0zp80AwZmQpX42Sbklia9LS4vFSXAqKKOCcv7hv-o9RaGeOBOoOJ126NydvHyQR42HYynx0a6lVPMymBV0hIbfHbJ1Zprn/s72-c/formula_area_of_triangle_3_sides.jpg" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6028190158486780364</id><published>2018-03-21T15:23:00.001+05:00</published><updated>2018-03-22T04:44:38.059+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Program Temperature Conversion Celsius To Fahrenheit Formula"/><category scheme="http://www.blogger.com/atom/ns#" term="Easyway How to Write a C++ Program for C++ Program Temperature Conversion Celsius To Fahrenheit Formula"/><title type='text'>C++ Program Temperature Conversion Celsius To Fahrenheit Formula</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
The formula for converting temperature in Celsius to Fahrenheit is:&lt;br /&gt;
&lt;b style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-family: lora;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;f=9.0/5.0 * c&amp;nbsp;+ 32;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;lora&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;It means that User input = temperature in Celsius&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;lora&amp;quot;;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;and output is temperature in Fahrenheit.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5x-Gq4GkkcqHvlTyoScA8oNZKMJo0EaOPyg7v8G4zdNsjprZLLHXSsnmEbL3qX102-3utC-faRvnL2xWKySn5ypO330MiNcHhQVhPUTYzvHy2zFxaHXZNAocEiLV4CxArm_Wp4O82l0Fn/s1600/temperature_c_plus_plus_program_input_teperature_in_celsius_fahrenheit_conversion.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway Temperature Conversion C++ Program Celsius Into Fahrenheit Scale Formula - C++ Source Code&quot; border=&quot;0&quot; data-original-height=&quot;429&quot; data-original-width=&quot;646&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5x-Gq4GkkcqHvlTyoScA8oNZKMJo0EaOPyg7v8G4zdNsjprZLLHXSsnmEbL3qX102-3utC-faRvnL2xWKySn5ypO330MiNcHhQVhPUTYzvHy2zFxaHXZNAocEiLV4CxArm_Wp4O82l0Fn/s1600/temperature_c_plus_plus_program_input_teperature_in_celsius_fahrenheit_conversion.jpg&quot; title=&quot;Easyway Temperature Conversion C++ Program Celsius Into Fahrenheit Scale Formula - C++ Source Code&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;
Easyway Temperature Conversion C++ Program&amp;nbsp;Celsius Into Fahrenheit Scale Formula - C++&amp;nbsp;Source Code&lt;/h2&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;Easyway Temperature Conversion C++ Program&amp;nbsp;Celsius Into Fahrenheit Scale Formula - C++&amp;nbsp;Source Code&lt;/h2&gt;
&lt;span style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-family: &amp;quot;lora&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;//Turbo C++ 3.0 IDE Easyway C++ Programs&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;#include&amp;lt;iostream.h&amp;gt;&amp;nbsp;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;#include&amp;lt;conio.h&amp;gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;void main()&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;{&amp;nbsp;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;float c,f;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;cout&amp;lt;&amp;lt; &quot;Enter Temperature in Celsius= &quot;;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;cin&amp;gt;&amp;gt;c;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;f=9.0/5.0 * c + 32;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;cout&amp;lt;&amp;lt;&quot;Temperature in Fahrenheit=&quot;&amp;lt;&amp;lt;f;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;getche();&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;}&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-family: &amp;quot;lora&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-family: &amp;quot;lora&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;
Output Result of&amp;nbsp; Temperature Conversion C++ Program&amp;nbsp;Celsius Into Fahrenheit Scale Formula - C++&amp;nbsp;Source Code&lt;/h2&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjztlmAOlnXi_o-rnx5f5EAxztXnuxmt0d-HOCMeUqWt1m0R1UwxKchdG-GC6xsBMsQpMBnwsqzNMp035DRYPx1yCm7OHEYV_fQMumsBT5BI962g1z4fTaG-eEDj0_NntUW5Iug-zT9tpC_/s1600/program_input_teperature_in_celsius_calculate_fahrenheit_conversion.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Output Result of  Temperature Conversion C++ Program Celsius Into Fahrenheit Scale Formula - C++ Source Code&quot; border=&quot;0&quot; data-original-height=&quot;163&quot; data-original-width=&quot;643&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjztlmAOlnXi_o-rnx5f5EAxztXnuxmt0d-HOCMeUqWt1m0R1UwxKchdG-GC6xsBMsQpMBnwsqzNMp035DRYPx1yCm7OHEYV_fQMumsBT5BI962g1z4fTaG-eEDj0_NntUW5Iug-zT9tpC_/s1600/program_input_teperature_in_celsius_calculate_fahrenheit_conversion.jpg&quot; title=&quot;Output Result of  Temperature Conversion C++ Program Celsius Into Fahrenheit Scale Formula - C++ Source Code&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;
Output Result of&amp;nbsp; Temperature Conversion C++ Program&amp;nbsp;Celsius Into Fahrenheit Scale Formula - C++&amp;nbsp;Source Code&lt;/h2&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
You would also like to view:&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Write A C++ Program To Convert Fahrenheit Temperature Into Centigrade with formula c= 5.0 / 9.0 x (f - 32)&lt;/h2&gt;
&lt;h3&gt;
&lt;a href=&quot;https://easycppprogramming.blogspot.com/2011/11/program-temperature-conversion.html&quot;&gt;Program Temperature Conversion Algorithm Flowchart&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6028190158486780364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/temperature-conversioninputcelsiusfahrenheitc-plus-plus-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6028190158486780364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6028190158486780364'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/temperature-conversioninputcelsiusfahrenheitc-plus-plus-program.html' title='C++ Program Temperature Conversion Celsius To Fahrenheit Formula'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5x-Gq4GkkcqHvlTyoScA8oNZKMJo0EaOPyg7v8G4zdNsjprZLLHXSsnmEbL3qX102-3utC-faRvnL2xWKySn5ypO330MiNcHhQVhPUTYzvHy2zFxaHXZNAocEiLV4CxArm_Wp4O82l0Fn/s72-c/temperature_c_plus_plus_program_input_teperature_in_celsius_fahrenheit_conversion.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-393411348556811059</id><published>2018-03-21T06:34:00.000+05:00</published><updated>2018-03-21T08:11:54.849+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Use of Conditional Operator to check even odd number"/><category scheme="http://www.blogger.com/atom/ns#" term="Write a C++ Program To Check a Number For Even Odd Using Conditional Operator Ternary Operator"/><title type='text'>Write a C++ Program To Check a Number For Even Odd Using Conditional Operator Ternary Operator </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is the C++&amp;nbsp;source code&amp;nbsp; for &lt;u&gt;&lt;b&gt;the program that will input an integer number and will &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;b&gt;check this number whether it is even or odd&lt;/b&gt;&lt;/u&gt;. But this program will not use if else statement for checking this number for even / odd. Rather it will use &lt;b&gt;&lt;u&gt;C++&amp;nbsp;Conditional operator / Ternary operator&lt;/u&gt;&lt;/b&gt; for this purpose as shown in the following figure of the even odd program using ternary operator:&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRgc7zHdqVMiQsdsTvw-R-J2dt1BDiJRXXKZKM0HQegnjZ0LqqnuNdaIENksRkjJrm9VCeuIj8bBQ_HH3XGJdgPau8lMYe9aNniYjIGs9_rWU4cf5VrvXJMMCzsoT2N-C_RBP4Y2JMC59U/s1600/ternary_conditional_operator_program_even_odd_c_plus_plus_easyway.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway C++ Program to check a number for even odd using conditional operator or ternary operator&quot; border=&quot;0&quot; data-original-height=&quot;400&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRgc7zHdqVMiQsdsTvw-R-J2dt1BDiJRXXKZKM0HQegnjZ0LqqnuNdaIENksRkjJrm9VCeuIj8bBQ_HH3XGJdgPau8lMYe9aNniYjIGs9_rWU4cf5VrvXJMMCzsoT2N-C_RBP4Y2JMC59U/s1600/ternary_conditional_operator_program_even_odd_c_plus_plus_easyway.jpg&quot; title=&quot;Easyway C++ Program to check a number for even odd using conditional operator or ternary operator&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Easyway C++ Program to check a number for even odd using conditional operator or ternary operator&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Here is the C++ program:

&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;iostream.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;conio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;void main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; int n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;clrscr();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter a number to check for Even / Odd = &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; (n%2==0) ? cout&amp;lt;&amp;lt;&quot;Number is Even&quot; : cout&amp;lt;&amp;lt;&quot;Number is odd&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; getch();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;A sample execution of the program even odd with conditional operator is as follows:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;when user enters 10 the output will be Number is Even&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;and when user enters 111 then output message shown will be Number is Odd.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzw4AqCKb70V1SITXm8AEIKgwJIHPu0TFxMTyOjn62jnOLHxt0hx7iUu5D6asJRu74iHzf0Fvk1I6awm1whydSLQkaMB2PS6BDM5Y96Ke0Bw1TByaCQaCjqRSddFv8ovAbKqpsl7_SrBR3/s1600/ternary_conditional_operator_program_even_odd_c_plus_plus_easyway_output_sample_run.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Program C++ To Check number even or odd with ternary operator / conditional operator output&quot; border=&quot;0&quot; data-original-height=&quot;262&quot; data-original-width=&quot;427&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzw4AqCKb70V1SITXm8AEIKgwJIHPu0TFxMTyOjn62jnOLHxt0hx7iUu5D6asJRu74iHzf0Fvk1I6awm1whydSLQkaMB2PS6BDM5Y96Ke0Bw1TByaCQaCjqRSddFv8ovAbKqpsl7_SrBR3/s1600/ternary_conditional_operator_program_even_odd_c_plus_plus_easyway_output_sample_run.jpg&quot; title=&quot;Program C++ To Check number even or odd with ternary operator / conditional operator output&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Program C++ To Check number even or odd with ternary operator / conditional operator output&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Explanation of Logic behind : Even / Odd Program i C++ with Ternary Operator or Conditional Operator&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The main statement of this program is using Conditional operator.&amp;nbsp;&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;The conditional operator has the syntax:&lt;/span&gt;&lt;/h4&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #6aa84f; font-size: large;&quot;&gt;(condition)? case_if_true : case_if_false ;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Working of Conditional Operator&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;The condition will be checked first of all, if condition is true then first statement is executed otherwise second statement is executed, as shown in the following line of code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;{&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Note: here in true_case and false_case we can use only:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;arithematic expression, constant value, input / output statement;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f1c232; font-size: large;&quot;&gt;(n%2==0) ? cout&amp;lt;&amp;lt;&quot;Number is Even&quot; : cout&amp;lt;&amp;lt;&quot;Number is odd&quot;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;so if we enter 10&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;condition becomes 10%2==0&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;We know that % gives remainder so 10%2 will give zero&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;so condition becomes &lt;span style=&quot;background-color: #3d85c6;&quot;&gt;0 == 0&lt;/span&gt; which is true&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;so first statement is executed and output message is displayed: &lt;span style=&quot;color: red;&quot;&gt;Number is Even&lt;/span&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/393411348556811059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-check-number-even-odd-conditional-ternary-operator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/393411348556811059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/393411348556811059'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-check-number-even-odd-conditional-ternary-operator.html' title='Write a C++ Program To Check a Number For Even Odd Using Conditional Operator Ternary Operator '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRgc7zHdqVMiQsdsTvw-R-J2dt1BDiJRXXKZKM0HQegnjZ0LqqnuNdaIENksRkjJrm9VCeuIj8bBQ_HH3XGJdgPau8lMYe9aNniYjIGs9_rWU4cf5VrvXJMMCzsoT2N-C_RBP4Y2JMC59U/s72-c/ternary_conditional_operator_program_even_odd_c_plus_plus_easyway.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-3597666314317167328</id><published>2018-03-17T15:55:00.002+05:00</published><updated>2018-04-08T01:13:44.336+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Plus Plus Program to Calculate Factorial of Number Using Do While Loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Factorial Program by do while loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Write program to calculate factorial by do while loop"/><title type='text'>C Plus Plus Program to Calculate Factorial of Number Using Do While Loop</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk5_S8SDft_vGLJG5miUfMRzik50AL3fhnFiZAoz_2V1IeOIxJyQUj0FCwt_NeOYbclaRDOp8nee6PI5SzVV7rrqAGqILFwGyzRUFStssPbucNo3D94zEVT9sP95eaFXDDmFWs218s1jfx/s1600/factorialusingdowhileloopcplusplusprogram.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Program To Calculate Factorial of a Number Using do ... while Loop&quot; border=&quot;0&quot; data-original-height=&quot;614&quot; data-original-width=&quot;652&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk5_S8SDft_vGLJG5miUfMRzik50AL3fhnFiZAoz_2V1IeOIxJyQUj0FCwt_NeOYbclaRDOp8nee6PI5SzVV7rrqAGqILFwGyzRUFStssPbucNo3D94zEVT9sP95eaFXDDmFWs218s1jfx/s1600/factorialusingdowhileloopcplusplusprogram.jpg&quot; title=&quot;Program To Calculate Factorial of a Number Using do ... while Loop&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;
Program To Calculate Factorial of a Number Using do ... while Loop&lt;/h2&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;What is Factorial?&lt;/h3&gt;
&lt;br /&gt;
factorial of a number is calculated by multiplying all the integer numbers from given number n to 1.&lt;br /&gt;
For example, factorial of&amp;nbsp; 3 = 3 x 2 x 1.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
What is do while Loop in C++ ?&lt;/h3&gt;
&lt;br /&gt;
do while loop is the third loop provided by C++. First two are for loop and while loop. The do while loop is used to execute a set of one or more statements repeatedly as long as the given condition remains true.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
The main difference between while loop and do while loop is that&lt;/h4&gt;
&amp;nbsp;the syntax of do while loop places the condition after the body of loop. The effect of this is that the loop body of do while loop is executed at least once irrespective of the given condition for loop is true or false for first time.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
The syntax of do while loop is:&lt;/h3&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;font-size: large;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp; statement;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; while&amp;nbsp; ( condition );&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; or for a set two or of statements the syntax of do while loop will be as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;font-size: large;&quot;&gt; do&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; statement 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; statement 2;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; .&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; .&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; .&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; statement n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp; while ( condition );&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Simple example of do while loop to display first 5 numbers 1 to 5&lt;/h3&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;font-size: large;&quot;&gt; int i=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; do&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;i&amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( i&amp;lt;=5 );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; output:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now we start writing the the program to calculate factorial of a number provided by the user at runtime using do ... while loop&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;// This program will calculate factorial of a given number provided //by user at run time using do while loop&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;iostream.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;#include&amp;lt;conio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;void main( )&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; int num,&amp;nbsp; i, fact;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clrscr( );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter a number to calculate Factorial=&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;num;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fact= 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; i = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; do&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fact = fact * i;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; i++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( i &amp;lt;= num );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Factorial of = &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt; &quot; = &quot;&amp;lt;&amp;lt;fact;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getche();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Sample Output of&amp;nbsp; Program To Calculate Factorial of a Number Using do ... while Loop&lt;/h2&gt;
Enter a Number to Calculate Factorial: 4&lt;br /&gt;
Factorial of 4 = 24&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
More Programs of Factorial are as follows:&lt;/h2&gt;
&lt;br /&gt;
&lt;a dir=&quot;ltr&quot; href=&quot;https://easycppprogramming.blogspot.com/search/label/Factorial%20By%20For%20Loop%20Statement&quot;&gt;Factorial By For Loop Statement&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;a dir=&quot;ltr&quot; href=&quot;https://easycppprogramming.blogspot.com/search/label/Program%20Factorial%20by%20While%20Loop%20Logic&quot;&gt;Program Factorial by While Loop Logic&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/3597666314317167328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-factorail-of-number-do-while-loop-c-plus-plus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3597666314317167328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/3597666314317167328'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2018/03/program-factorail-of-number-do-while-loop-c-plus-plus.html' title='C Plus Plus Program to Calculate Factorial of Number Using Do While Loop'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk5_S8SDft_vGLJG5miUfMRzik50AL3fhnFiZAoz_2V1IeOIxJyQUj0FCwt_NeOYbclaRDOp8nee6PI5SzVV7rrqAGqILFwGyzRUFStssPbucNo3D94zEVT9sP95eaFXDDmFWs218s1jfx/s72-c/factorialusingdowhileloopcplusplusprogram.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-7736784003400972629</id><published>2014-07-17T15:20:00.001+05:00</published><updated>2019-05-23T08:42:38.144+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ Editor Free Download"/><category scheme="http://www.blogger.com/atom/ns#" term="Download and Install Turbo C++ Full Screen Windows 7 Vista"/><category scheme="http://www.blogger.com/atom/ns#" term="Download Free C++ IDE for Windows OS"/><title type='text'>Download and Install Turbo C++ Full Screen IDE for Windows 7 Vista</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today we will discuss &lt;b&gt;How to Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
What is Turbo C++?&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;/h3&gt;
Turbo C++ 3.0 is the most popular OLD is GOLD Compiler for C language and C++ Language. in many countries students, normally, use Turbo C++ 3.0 for learning C / C++ programming.&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;They write their first C Language Program or C++ Program in Turbo C IDE. You can download and install Turbo C++ 3.0 in easy steps as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Link for &lt;b&gt;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&lt;/b&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://www.mediafire.com/download/32v8k1kdweigh6c/Turbo-c%2B%2B-downlad-windows-7-vista-full-screen.zip&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&lt;/b&gt;&lt;/a&gt; &lt;/b&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://www.mediafire.com/download/32v8k1kdweigh6c/Turbo-c%2B%2B-downlad-windows-7-vista-full-screen.zip&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;
&lt;img alt=&quot;How to Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&quot; border=&quot;0&quot; data-original-height=&quot;152&quot; data-original-width=&quot;332&quot; height=&quot;146&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu9lWe0LDgY5EYenJpXVEkTb6yLyuQMvMk6TeaU16BvHKSKzqNe6mGEnnJcggn53iIRbgKRBmPqBygMH12noohIDMPB5-UcY4S9Jef2ARO7-Ign5qAspwaSVkk3Kz5OvAbZqXzZgxuMXY1/s320/download_turbo_cplusplus_ide_free_windows.jpg&quot; title=&quot;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://draft.blogger.com/null&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&lt;/b&gt;&lt;/a&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
How To &lt;b&gt;Install Turbo C++ With Full Screen IDE for Windows 7 and Vista&lt;/b&gt;.&lt;/h3&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;/ol&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp;After you have downloaded the Turbo C++ installation zip file from mediafire website , extract this file.&lt;br /&gt;
&lt;br /&gt;
Double click on the Turbo C++ installation file to start setup. Click on Next button.&lt;br /&gt;
Images are given below to guide you the Installation Process of Turbo C++ IDE.&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvNtHnn1PADYXaIIi2PR-D0NAWd7A7X_uZXer4bg30YHvTNmxT0GkokYygePdv8YHg2zdHCuGcTR7gRatWt9T4n9VUB8wYg6peN9KLdiL197wfnNZm6oUXF4f9UJ5zo-9S5N7D8ucftUIR/s1600/full-screen-turbo-c-windows-7-vista-setup-1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Download and Install Turbo C++ Compiler With Full Screen IDE for Windows 7 and Vista&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvNtHnn1PADYXaIIi2PR-D0NAWd7A7X_uZXer4bg30YHvTNmxT0GkokYygePdv8YHg2zdHCuGcTR7gRatWt9T4n9VUB8wYg6peN9KLdiL197wfnNZm6oUXF4f9UJ5zo-9S5N7D8ucftUIR/s1600/full-screen-turbo-c-windows-7-vista-setup-1.jpg&quot; title=&quot;Download and Install Turbo C++ Compiler With Full Screen IDE for Windows 7 and Vista&quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
Accept the terms and click on install button.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3XCcQI8IUehJhDyNe_mu4Vou-UidgBt8DIDECkqLZI8MHWr5BBK_IqK-NuSH9Fh_CylAnhOqE2DPQe-i_DTcXE8uwBtVNT7MAj8HCdtJ0C0kokrHQcjXQ3izPLNteb-WErKEgWYtNDTTu/s1600/full-screen-turbo-c-windows-7-vista-setup-2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista step 2&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3XCcQI8IUehJhDyNe_mu4Vou-UidgBt8DIDECkqLZI8MHWr5BBK_IqK-NuSH9Fh_CylAnhOqE2DPQe-i_DTcXE8uwBtVNT7MAj8HCdtJ0C0kokrHQcjXQ3izPLNteb-WErKEgWYtNDTTu/s1600/full-screen-turbo-c-windows-7-vista-setup-2.jpg&quot; title=&quot;Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista step 2&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Click on Finish button to end the setup. Congratulations! Now you can learn C++ computer programming in Turbo C++ IDE. You can write and run your first C++ Program in Turbo C IDE.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;steps to Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista step 3&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM_eCNs4C7aCxhr02IFbhHfNKpp2ZR_q1e8lDBWz4bx4bqTqxeb5MIvc-3DmteQLPYy6RJTXaK5tBvzBE6fO9YcqiEoMnQucv2_fJH2mO66g9xnn4dUxu85ieHku7lITPznEJ8nXaSj_9W/s1600/full-screen-turbo-c-windows-7-vista-setup-3.jpg&quot; title=&quot;steps to Download and Install Turbo C++ With Full Screen IDE for Windows 7 and Vista step 3&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Click on start button and click on Turbo C++ icon.&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZOv0sCy5IKezEdmP0IBhawIsYnMLtTLhyz76AKX2dH-nL4rgSmLPcOLpPtMw6HB6VQTu7Fy1yK1x36lUDqM5GTtCKru3IW9hdjUXmD_kh55PoI7bdmJxn3INQlOdH_DyUV7te3FoUKALn/s1600/full-screen-turbo-c-windows-7-vista-setup-4.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How To Run Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZOv0sCy5IKezEdmP0IBhawIsYnMLtTLhyz76AKX2dH-nL4rgSmLPcOLpPtMw6HB6VQTu7Fy1yK1x36lUDqM5GTtCKru3IW9hdjUXmD_kh55PoI7bdmJxn3INQlOdH_DyUV7te3FoUKALn/s1600/full-screen-turbo-c-windows-7-vista-setup-4.jpg&quot; title=&quot;How To Run Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
Click on File menu and select New.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1eB0w8SzwV6pOpchPaF4xI6kqse-699hI_S9tXiwSSDr5buiXWs0gVG_ottXOemW2UwU-tFYWvtezT47CJZR_kgxZjQi_BC52G39B0_oojuCEuNPgJD6pZMCkCaL_KQwk8kSo9dFcdK2c/s1600/full-screen-turbo-c-windows-7-vista-setup-5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How To Write First Program in Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1eB0w8SzwV6pOpchPaF4xI6kqse-699hI_S9tXiwSSDr5buiXWs0gVG_ottXOemW2UwU-tFYWvtezT47CJZR_kgxZjQi_BC52G39B0_oojuCEuNPgJD6pZMCkCaL_KQwk8kSo9dFcdK2c/s1600/full-screen-turbo-c-windows-7-vista-setup-5.jpg&quot; title=&quot;How To Write First Program in Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Type the first program as shown in the above picture. Click on RUN menu and select Run command. The output of the program will be shown as the following picture:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhDGI_O6AYi8pc2H9q0TDErauu1U7aTCXD4v3BtTIGksXyKlgdFprPTG0NIeXC2UOdAx8nHgJSTU750Q-PSl4b2Q8QheUkNLgDHLP5bZQUFXLNfvFHeLzqQHgC_fTUx531UQhQdyQ_1Wpo/s1600/full-screen-turbo-c-windows-7-vista-setup-6.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;output in Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhDGI_O6AYi8pc2H9q0TDErauu1U7aTCXD4v3BtTIGksXyKlgdFprPTG0NIeXC2UOdAx8nHgJSTU750Q-PSl4b2Q8QheUkNLgDHLP5bZQUFXLNfvFHeLzqQHgC_fTUx531UQhQdyQ_1Wpo/s1600/full-screen-turbo-c-windows-7-vista-setup-6.jpg&quot; title=&quot;output in Turbo C++ With Full Screen IDE for Windows 7 and Vista &quot; /&gt;&lt;/a&gt;&lt;/div&gt;
End of the C++ Tutorial &lt;u&gt;&lt;i&gt;&lt;b&gt;How To Download, Install Turbo C++ With Full Screen IDE for Windows 7 and Vista and &lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Write and Run First Program&lt;/b&gt;&lt;/i&gt;&lt;/u&gt; &lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/7736784003400972629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/07/download-install-turbo-c-full-screen-windows-7-vista.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7736784003400972629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7736784003400972629'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/07/download-install-turbo-c-full-screen-windows-7-vista.html' title='Download and Install Turbo C++ Full Screen IDE for Windows 7 Vista'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu9lWe0LDgY5EYenJpXVEkTb6yLyuQMvMk6TeaU16BvHKSKzqNe6mGEnnJcggn53iIRbgKRBmPqBygMH12noohIDMPB5-UcY4S9Jef2ARO7-Ign5qAspwaSVkk3Kz5OvAbZqXzZgxuMXY1/s72-c/download_turbo_cplusplus_ide_free_windows.jpg" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6808837910664973892</id><published>2014-06-10T06:33:00.001+05:00</published><updated>2018-03-17T19:19:09.010+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm and Program of Hours Conversion"/><title type='text'>C Plus Plus Program Conversion of Hours into Weeks Days Hours</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today, we are going to discuss a simple program logic that uses only input, output and assignment statements along with variable declarations.&lt;br /&gt;
&lt;br /&gt;
Points of Discussion are:&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7P8bdGQpQAA9LGxXtVafefX7b_B7QRezHjS_xzzELkMsqEajVkKNeKi44A1RGhjfMDwHY9oNwS1VLTJc53aCxJ-wSft3V4byzh5_2uSCxfZLq8ALIVPIUe-Q-8I3OFVW4V6J4FyW2ltPW/s1600/program_c_plus_plus_change_convert_hours.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway How to write c++ program convert hours into weeks days hours&quot; border=&quot;0&quot; data-original-height=&quot;180&quot; data-original-width=&quot;453&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7P8bdGQpQAA9LGxXtVafefX7b_B7QRezHjS_xzzELkMsqEajVkKNeKi44A1RGhjfMDwHY9oNwS1VLTJc53aCxJ-wSft3V4byzh5_2uSCxfZLq8ALIVPIUe-Q-8I3OFVW4V6J4FyW2ltPW/s1600/program_c_plus_plus_change_convert_hours.jpg&quot; title=&quot;Easyway How to write c++ program convert hours into weeks days hours&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Easyway How to write c++ program convert hours into weeks days hours&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;C++ Program: Input Hours Convert into Weeks, Days and Hours.&lt;/li&gt;
&lt;li&gt;Algorithm of the Hours Conversion Program&lt;/li&gt;
&lt;li&gt;C++ Code of the Hours Conversion Program.&lt;/li&gt;
&lt;li&gt;Understanding Logic of The Hours into Week, Day and Hours Program&lt;/li&gt;
&lt;/ul&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjilxUHf0FcX6hyugaQrI2czW_JrtIVVd_uyGFnFKDy7I5vjI4M8QyYfW0iA1ld6zJVNWs8clUiJR5gWpys_uC3lLFEBbNyNkOlTeC4hMh7u6CD3Wwe-HdoeAGjrnaq6Z0DaJMKPArHxjNj/s1600/c-plus-plus-program-hours-conversion-weeks-days.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;C Plus Plus to convert hours into weeks days and hours &quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjilxUHf0FcX6hyugaQrI2czW_JrtIVVd_uyGFnFKDy7I5vjI4M8QyYfW0iA1ld6zJVNWs8clUiJR5gWpys_uC3lLFEBbNyNkOlTeC4hMh7u6CD3Wwe-HdoeAGjrnaq6Z0DaJMKPArHxjNj/s1600/c-plus-plus-program-hours-conversion-weeks-days.jpg&quot; title=&quot;C Plus Plus to convert hours into weeks days and hours &quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;C Plus Plus to convert hours into weeks days and hours &lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2&gt;
ALGORITHM : Hours Conversion&lt;/h2&gt;
This algorithm is used to input hours and convert into weeks, days and hours.&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Start&lt;/li&gt;
&lt;li&gt;Input Hours&lt;/li&gt;
&lt;li&gt;Calculate Weeks = Hours / 168&lt;/li&gt;
&lt;li&gt;Calculate Hours = Hours Mod 168&lt;/li&gt;
&lt;li&gt;Calculate Days = Hours / 24&lt;/li&gt;
&lt;li&gt;Calculate Hours = Hours Mod 24&lt;/li&gt;
&lt;li&gt;Display &quot;Weeks=&quot;, Weeks&lt;/li&gt;
&lt;li&gt;Display &quot;Days=&quot;, Days &lt;/li&gt;
&lt;li&gt;Display &quot;Hours =&quot;, Hours&lt;/li&gt;
&lt;li&gt;End&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;h2&gt;
C++ Code: Program Hours Conversion into Weeks, Days and Hours.&lt;/h2&gt;
/* This program is used to input hours from the user. Then this algorithm &quot;Hours Conversion&quot; will convert hours into weeks, days and hours.*/&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clrscr();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int h, w, d, hrs;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter Hours=&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;hrs;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; h = hrs; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w = hrs / 168;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hrs = hrs % 168;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d = hrs / 24;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hrs = hrs % 24;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Total Hours input = &quot;&amp;lt;&amp;lt;h&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Weeks =&quot;&amp;lt;&amp;lt;w&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Days =&quot;&amp;lt;&amp;lt;d&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Hours =&quot;&amp;lt;&amp;lt;hrs;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
OUTPUT of Sample Run of The Program Hours Conversion&lt;/h2&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Enter Hours= 200&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Total Hours input =200&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Weeks = 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Days =1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Hours =8&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Logic of The Program Hours Conversion&lt;/h2&gt;
&lt;br /&gt;
We know that:&lt;br /&gt;
1 day = 24 hours&lt;br /&gt;
so 1 week = 24 x 7 = 168 hours&lt;br /&gt;
&lt;br /&gt;
Therefore we will divide total hours by 168 to get weeks.&lt;br /&gt;
weeks = 200 / 168 will give 1 week.&lt;br /&gt;
Now to calculate remaining hours we will get remainder of the division 200 % 168&lt;br /&gt;
This will give remaining hours = 32&lt;br /&gt;
&lt;br /&gt;
To get days, we will divide remaining hours by 24&lt;br /&gt;
so 32 / 24 will give 1 day.&lt;br /&gt;
&lt;br /&gt;
Now we will calculate remaining hours by remainder 32 % 24 that will give the result 8 hours.&lt;br /&gt;
&lt;br /&gt;
So the output 1 week, 1 day and 8 hours.&lt;br /&gt;
&lt;br /&gt;
If you enjoyed the C++ Learning Through Example program Logic Understanding, Please share this blog on Social media. Thanks!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6808837910664973892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/06/c-plus-plus-program-conversion-of-hours.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6808837910664973892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6808837910664973892'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/06/c-plus-plus-program-conversion-of-hours.html' title='C Plus Plus Program Conversion of Hours into Weeks Days Hours'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7P8bdGQpQAA9LGxXtVafefX7b_B7QRezHjS_xzzELkMsqEajVkKNeKi44A1RGhjfMDwHY9oNwS1VLTJc53aCxJ-wSft3V4byzh5_2uSCxfZLq8ALIVPIUe-Q-8I3OFVW4V6J4FyW2ltPW/s72-c/program_c_plus_plus_change_convert_hours.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-8111581451794169563</id><published>2014-02-16T15:11:00.001+05:00</published><updated>2019-05-28T22:14:32.902+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Plus Plus Program Reverse Number Conversion"/><category scheme="http://www.blogger.com/atom/ns#" term="Convert a Number into Reverse Number C++ Program"/><category scheme="http://www.blogger.com/atom/ns#" term="Easy Reverse Number C++ Program"/><category scheme="http://www.blogger.com/atom/ns#" term="Reverse an input number by user C++ Program solution"/><title type='text'>Convert a Number into Reverse Number Program in C Plus Plus</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
C++ Reverse Number Conversion Program Logic&lt;/h2&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitnK59xmEsauc7wonVpdMZP500xSUFjkCXNi6ipgAZSnFBbqnhCLOh1MC4kOS0wpFRd137mHABCPIP8wefaLwGVoiFKBzO2tWeS40-5Lcx8BdGVWwW3_qj6l-hWH5T1IE7KvS7xRBo9aX0/s1600/perfect-c-plus-plus-reverse-num-conversion-program-solved.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Reverse Number Program logic in C Plus Plus using While Loop&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitnK59xmEsauc7wonVpdMZP500xSUFjkCXNi6ipgAZSnFBbqnhCLOh1MC4kOS0wpFRd137mHABCPIP8wefaLwGVoiFKBzO2tWeS40-5Lcx8BdGVWwW3_qj6l-hWH5T1IE7KvS7xRBo9aX0/s1600/perfect-c-plus-plus-reverse-num-conversion-program-solved.jpg&quot; title=&quot;Reverse Number Program in C Plus Plus using While Loop&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Reverse Number Program in C Plus Plus using While Loop&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
Q: &lt;b&gt;Write a C++ Program to input an integer number and display its Reverse Number.&lt;/b&gt; For example if the input is the number 123, the Reverse Number will be 321.&lt;br /&gt;
&lt;br /&gt;
Reverse Number Logic in common programming is very important. Although, it is difficult for beginner programmers, you must learn and understand REVERSE NUMBER Program in C++ or JAVA. This will be helpful for further improvements in your programming logic. &lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL0EsTItjjwq6VO6EKSW4v7GbhST742DpGTr_9HJhPvulx5cdG3hs-EpeTc82bwB8XNjY-Wx4UIUTFtNQ-1cMbdF27qp2lFO3-u1wQpKpFXpfWsSwuukGJfhLkKs0MtMMdfS6Pzh8-J7Kc/s1600/convert-reverse-number-program-c-plus-plus.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Reverse the input number program in C++&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL0EsTItjjwq6VO6EKSW4v7GbhST742DpGTr_9HJhPvulx5cdG3hs-EpeTc82bwB8XNjY-Wx4UIUTFtNQ-1cMbdF27qp2lFO3-u1wQpKpFXpfWsSwuukGJfhLkKs0MtMMdfS6Pzh8-J7Kc/s1600/convert-reverse-number-program-c-plus-plus.gif&quot; title=&quot;Reverse the input number program in C++&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Reverse the input number program in C++&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;First of all we suppose that the number entered is 123.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Let the given number num = 123 &lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Copy the number in temporary variable temp so that temp = 123&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;h3&gt;
First Iteration of While Loop &lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;We start a while loop with condition temp&amp;gt;0. Since temp=123 so loop will start for first time.&lt;/li&gt;
&lt;li&gt;Now we will divide number 123 by 10 so that the remainder R = 3 and Quotient Q = 12&lt;/li&gt;
&lt;li&gt;Put the values in statement rev = rev * 10&amp;nbsp;+ R &lt;/li&gt;
&lt;li&gt;rev = 0 * 10 + 3&lt;/li&gt;
&lt;li&gt;rev = 3&lt;/li&gt;
&lt;li&gt;Assign the value of Quotient Q to temp so that temp = 12 now.&lt;/li&gt;
&lt;li&gt;Since temp 12 is &amp;gt;0, so the while loop will execute again.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
Second Iteration of While Loop&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Now we will divide number temp 12 by 10 so that the remainder R = 2 and Quotient Q = 1&lt;/li&gt;
&lt;li&gt;Put the values in statement rev = rev * 10&amp;nbsp;+ R &lt;/li&gt;
&lt;li&gt;rev = 3 * 10 + 2&lt;/li&gt;
&lt;li&gt;rev = 30+2&lt;/li&gt;
&lt;li&gt;rev = 32 &lt;/li&gt;
&lt;li&gt;Assign the value of Quotient Q to temp so that temp = 1 now.&lt;/li&gt;
&lt;li&gt;Since temp 1 is &amp;gt;0, so the while loop will execute again.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&amp;nbsp;Third Iteration of While Loop&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;Now we will divide number temp 1 by 10 so that the remainder R = 1 and Quotient Q = 0&lt;/li&gt;
&lt;li&gt;Put the values in statement rev = rev * 10&amp;nbsp;+ R &lt;/li&gt;
&lt;li&gt;rev = 32 * 10 + 1&lt;/li&gt;
&lt;li&gt;rev = 320+1&lt;/li&gt;
&lt;li&gt;rev = 321 &lt;/li&gt;
&lt;li&gt;Assign the value of Quotient Q to temp so that temp = 0 now.&lt;/li&gt;
&lt;li&gt;Since temp 0 is not &amp;gt;0, so the condition temp&amp;gt;0 will evaluate to false so that the while loop will terminate.&lt;/li&gt;
&lt;/ul&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRukRsYhv_d9po0kyEnm1khqmwyti2ApSDLu8Ua7w960PvepxJAG1NKZxVhhnfPp3uwceWYmUEyLRnvcfx44L-pBGi3c4FPZCrgUEhOfBRJJ30efH2hC6esrdomhG7K6kszQAaxZprn82y/s1600/reverse-number-program-code-in-c-plus-plus.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;While loop reverse a number program C++&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRukRsYhv_d9po0kyEnm1khqmwyti2ApSDLu8Ua7w960PvepxJAG1NKZxVhhnfPp3uwceWYmUEyLRnvcfx44L-pBGi3c4FPZCrgUEhOfBRJJ30efH2hC6esrdomhG7K6kszQAaxZprn82y/s1600/reverse-number-program-code-in-c-plus-plus.gif&quot; title=&quot;While loop reverse a number program&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;While loop reverse a number program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Conclusion&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;u&gt;&lt;b&gt; So the Required Reverse Number is 321.&lt;/b&gt;&lt;/u&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;h2&gt;
The Actual C++ Code of Reverse Number Program &lt;/h2&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;b&gt;Program to input a number, then display its Reverse number.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;(c) Www.EasyCppProgramming.Blogspot.Com&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;*/&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num, temp, rev=0, R, Q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clrscr();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter a number to reverse=&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = num;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( temp&amp;gt;0 )&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Q = temp/10;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R = temp % 10;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rev = rev*10 + R;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = Q;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\n The Reverse Number = &quot;&amp;lt;&amp;lt;rev;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/8111581451794169563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/02/convert-number-into-reverse-number.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/8111581451794169563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/8111581451794169563'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/02/convert-number-into-reverse-number.html' title='Convert a Number into Reverse Number Program in C Plus Plus'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitnK59xmEsauc7wonVpdMZP500xSUFjkCXNi6ipgAZSnFBbqnhCLOh1MC4kOS0wpFRd137mHABCPIP8wefaLwGVoiFKBzO2tWeS40-5Lcx8BdGVWwW3_qj6l-hWH5T1IE7KvS7xRBo9aX0/s72-c/perfect-c-plus-plus-reverse-num-conversion-program-solved.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-4783520536336065517</id><published>2014-01-16T21:15:00.004+05:00</published><updated>2018-05-23T12:31:38.281+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Explain  Insertion Sort Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Insertion Sort Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Insertion Sort Algorithm Example"/><category scheme="http://www.blogger.com/atom/ns#" term="Insertion Sort Program Source Code"/><category scheme="http://www.blogger.com/atom/ns#" term="Insertion Sort Program using C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting Algorithms Plus Programs"/><title type='text'>Insertion Sort Algorithm Trace Steps and C++ Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Today, we will discuss &lt;b&gt;Insertion Sort Algorithm Trace Steps on Sample Data and C++ Program implementation of Insertion Sort&lt;/b&gt;. First of all, we will:&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Define &lt;u&gt;Insertion Sort&lt;/u&gt;&lt;/li&gt;
&lt;li&gt;Explain the &lt;b&gt;working of Insertion Sort&lt;/b&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Design an algorithm of Insertion Sort&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Show trace steps of Insertion sort algorithm for sample data on paper.&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Finally, write down the actual code of Insertion sort program in C++. &lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
&amp;nbsp;&amp;nbsp;What is Insertion Sort?&lt;/h3&gt;
In Insertion sort, we have to insert elements in to correct position. First of all we find the correct position to insert for the key value under consideration. Secondly we will move other elements to make space for this new element (key value). Now we insert the new element at this space. Suppose there are the following elements in an array A to sort by insertion sort:
&lt;br /&gt;
&lt;h3&gt;
Working of Insertion Sort&lt;/h3&gt;
1. Let first item be trivially sorted.&lt;br /&gt;
2. Now we consider first two items of list. Place second item on its correct location.&lt;br /&gt;
3. In Third pass we will consider first three items from list. Insert the 3rd item at its correct location among location1, location2 and location3.&lt;br /&gt;
4. In 4th pass, insert the 4th item at its correct location among location1, location2, location3 and location4.&lt;br /&gt;
5. And so on.&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Algorithm of Insertion Sort &lt;/h3&gt;
&amp;nbsp;Algorithm: INSERTION-SORT(array)&lt;br /&gt;
&amp;nbsp;This algorithm takes Array &#39;array&#39; of size n numbers (array has index from 0 to n-1)as input. It sorts the given array in ascending order by INSERTION SORT method. i and j are integer variables used as index of array. temp is a temporary integer variable.&lt;br /&gt;
&amp;nbsp;1. &amp;nbsp; Repeat through step 6 for i ← 1 to n-1&lt;br /&gt;
&amp;nbsp;2.&amp;nbsp; &amp;nbsp;&amp;nbsp; temp&amp;nbsp; ← array[i]&lt;br /&gt;
&amp;nbsp;3.&amp;nbsp; &amp;nbsp; Repeat through&amp;nbsp; step 5 while ( j &amp;gt; 0 &amp;amp;&amp;amp; array[j-1] &amp;gt; temp)&lt;br /&gt;
&amp;nbsp;4.&amp;nbsp;&amp;nbsp;&amp;nbsp; array[j] ← array[j -1]&lt;br /&gt;
&amp;nbsp;5. &amp;nbsp;&amp;nbsp; j ← &amp;nbsp; j - 1&lt;br /&gt;
&amp;nbsp;6.&amp;nbsp;&amp;nbsp;&amp;nbsp; array[j]← temp&lt;br /&gt;
&amp;nbsp;7. &amp;nbsp;&amp;nbsp; End &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
 &lt;/h3&gt;
Insertion Algorithm Paper Tracing with data:a[0] ,a[1], a[2], a[3], a[4], a[5]&lt;br /&gt;
&amp;nbsp;5,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, &amp;nbsp;&amp;nbsp;&amp;nbsp; 4,&amp;nbsp; &amp;nbsp; &amp;nbsp; 6, &amp;nbsp; &amp;nbsp; 1, &amp;nbsp; &amp;nbsp; 3&lt;br /&gt;
1. First of all we suppose that the first element 5 is its correct place or trivially sorted.&lt;br /&gt;
&lt;br /&gt;
2. Now we consider second element 2. We have to insert 2 at its correct location from first two locations [0] and [1]. We will find its correct position from first two items 5 and 2.&lt;br /&gt;
3. Since 2 is less than 5, so the correct location of 2 is at array index[0].&lt;br /&gt;
4. We will move 5 from position [0] to [1].&lt;br /&gt;
5. Now we will place 2 at [0], so we have sorted first two items.&lt;br /&gt;
&lt;br /&gt;
6. Now array = 2,5,4,6,1,3 Consider 3rd item which is 4. Now we find its correct location from first three locations. So 4 will be inserted at location [1] between 2 and 5.&lt;br /&gt;
7. We move 5 to position [2] and place 4 on position [1]&lt;br /&gt;
8. So first three items are sorted with array = 2,4,5,6,1,3&lt;br /&gt;
&lt;br /&gt;
9. Now array = 2,4,5,6,1,3 &amp;nbsp; consider 4th item 6 and place on its correct location among first four locations.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; We know that 6 is at its correct location which is 4th location and by index it is [3].&lt;br /&gt;
&lt;br /&gt;
10. Now array is 2,4,5,6,1,3&amp;nbsp; consider 5th item which is 1. We know that its correct location between first&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; five items is number one that is position [0] by index.&lt;br /&gt;
11. So we move 6 on [4]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; we move 5 on [3]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; we move 4 on [2]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; we move 2 on [1]&lt;br /&gt;
12. Now place 1 on position [0], so the array items a[0] to a[4] are sorted&lt;br /&gt;
&lt;br /&gt;
13. Now array is 1,2,4,5,6,3 &amp;nbsp; consider 6th item which is 3.&lt;br /&gt;
14. We know that 3 will be inserted at location [2] between item 2 and item 4.&lt;br /&gt;
15. We move 6 to location [5]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; move 5 to [4]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; move 4 to [3]&lt;br /&gt;
16. Now place 3 at location [2]&lt;br /&gt;
17. Hence the whole array has been sorted now&amp;nbsp; &amp;nbsp;&amp;nbsp; 1,2,3,4,5,6&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;You can check this all process in the following picture of insertion sort paper tracing.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Insertion Sort Algorithm Trace Steps and Program&lt;/h3&gt;
&lt;i&gt;&lt;u&gt;&lt;b&gt;Image: Trace steps : Insertion Sort Algorithm Trace Steps and Program&lt;/b&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYbPOfK1-HVALQhLq_X0MOupxG_SljjvKIhZThOlYxLnIUerayWs9Cc3AE-XMqHpz2auraK-COElYEfzqJi-9fHM32enE3lA2tqHnHv02cufUYEJ8Rtsyc0Sm4dn0OXdWmcycXVwoM0usk/s1600/insertion-sorting-paper-trace-data-passes.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway C++ : Insertion sort Algorithm trace steps and C++ Program&quot; border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYbPOfK1-HVALQhLq_X0MOupxG_SljjvKIhZThOlYxLnIUerayWs9Cc3AE-XMqHpz2auraK-COElYEfzqJi-9fHM32enE3lA2tqHnHv02cufUYEJ8Rtsyc0Sm4dn0OXdWmcycXVwoM0usk/s1600/insertion-sorting-paper-trace-data-passes.gif&quot; title=&quot;Insertion Sort Algorithm Trace Steps and Program&quot; width=&quot;295&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Easyway C++ : Insertion sort Algorithm trace steps and C++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Program Insertion Sort in C++&lt;/h3&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
(c)EasyCppProgramming.Blogspot.Com&lt;br /&gt;
C++ is Simplified Here!&lt;br /&gt;
Target 1001 C++ Example Programs!&lt;br /&gt;
EasyCppProgramming.Blogspot.Com&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Program To Input an array and sort&lt;br /&gt;
// the array by Insertion Sort Algorithm&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int n, array[100], i, j, t;&lt;br /&gt;
&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\n/* Insertion sort Ascending order */\n&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter number of elements\n&quot;;&lt;br /&gt;
&amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter &quot;&amp;lt;&amp;lt;n&amp;lt;&amp;lt;&quot; numbers\n&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; for (i = 0; i &amp;lt; n; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;array[i];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for( i = 1;i &amp;lt; n; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = array[i];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ( j = i; j &amp;gt; 0 &amp;amp;&amp;amp; array[j-1] &amp;gt; temp; j--)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array[j] = array[j-1];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array[j] = temp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Sorted list in ascending order:\n&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; for (i = 0; i &amp;lt;= n - 1; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;array[i]&amp;lt;&amp;lt;endl;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp; return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Image: Sample Run of Program in Turbo C++ 3.0 - Insertion Sort Algorithm Trace Steps and Program &lt;/h4&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggzGWbwxAiQNTVrtQBQWZ6MM3ACbbPxrdiSVjPq4OAXL4Enjt8rOTcH-iYZ4PxoaVyeVUhRHauNyy8L2ZGzl9tlVBVtlw5LHT05sak0uejwBSAiv70fgb2jtO3clK-fnx8f8PQWx3BJpGW/s1600/insertion-sort-program-algorithm-in-cpp.gif&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway C++ : Insertion sort algorithm C++ Program Output Trace output&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggzGWbwxAiQNTVrtQBQWZ6MM3ACbbPxrdiSVjPq4OAXL4Enjt8rOTcH-iYZ4PxoaVyeVUhRHauNyy8L2ZGzl9tlVBVtlw5LHT05sak0uejwBSAiv70fgb2jtO3clK-fnx8f8PQWx3BJpGW/s1600/insertion-sort-program-algorithm-in-cpp.gif&quot; title=&quot;Easyway C++ : Insertion sort algorithm C++ Program Output Trace output&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Easyway C++ : Insertion sort algorithm C++ Program Output Trace output&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
&amp;nbsp;Another Insertion Sorting Example for sorting data: 5,2,3,8,1&lt;/h3&gt;
&lt;i&gt;Figure: ample data trace steps: Insertion Sort Algorithm Trace Steps and Program&lt;/i&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgQqROcBc57KvQVcYEJQ10EfR-fgjvevjK3zbLy0klDKe9VjcZBmxAHhcihimB8uufbfSZowSkRKkjOWtM5F-1ubi3hICskE6keGdbP8dwhGCBwpWg3rt9tlf4LG5gwDRXiGA3bJF_Uitm/s1600/insertion-sort-algorithm-execution-data-ascending.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Another Insertion Sorting Example for sorting data - Insertion Sort Algorithm Trace Steps and Program&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgQqROcBc57KvQVcYEJQ10EfR-fgjvevjK3zbLy0klDKe9VjcZBmxAHhcihimB8uufbfSZowSkRKkjOWtM5F-1ubi3hICskE6keGdbP8dwhGCBwpWg3rt9tlf4LG5gwDRXiGA3bJF_Uitm/s1600/insertion-sort-algorithm-execution-data-ascending.gif&quot; title=&quot;Another Insertion Sorting Example for sorting data&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;Insertion Sort Algorithm Trace Steps and Program - easyway C++ Program&lt;/i&gt;&lt;/td&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
So, we have completely discussed &lt;b&gt;Insertion Sort Algorithm Trace Steps and Program, &lt;/b&gt;if you have any question please do not hesitate to ask question in comments section, thanks.&lt;br /&gt;
&lt;br /&gt;
Further suggested Reading: Sorting Algorithms and Programs in C / C++&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;h4&gt;
&amp;nbsp;&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/bubble-sort-algorithm-and-program-logic.html&quot; target=&quot;_blank&quot;&gt;Bubble Sort Algorithm and Program Logic in C Plus Plus&lt;/a&gt; &lt;/h4&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/4783520536336065517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/insertion-sort-algorithm-trace-steps.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/4783520536336065517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/4783520536336065517'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/insertion-sort-algorithm-trace-steps.html' title='Insertion Sort Algorithm Trace Steps and C++ Program'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYbPOfK1-HVALQhLq_X0MOupxG_SljjvKIhZThOlYxLnIUerayWs9Cc3AE-XMqHpz2auraK-COElYEfzqJi-9fHM32enE3lA2tqHnHv02cufUYEJ8Rtsyc0Sm4dn0OXdWmcycXVwoM0usk/s72-c/insertion-sorting-paper-trace-data-passes.gif" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-7597448704879987695</id><published>2014-01-14T22:53:00.003+05:00</published><updated>2018-05-25T11:38:01.345+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bubble Sort Algorithm Trace Steps on Sample Data and C++ Program"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting Algorithms Plus Programs"/><title type='text'>Bubble Sort Algorithm Trace Steps on Sample Data and C++ Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Today, we will discuss &lt;b&gt;Bubble Sort Algorithm and Program Logic in CPP&lt;/b&gt; ( C++ ) programming language. We will study:&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;Definition of Bubble Sort Algorithm&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Trace steps for sample data or working of Bubble sorting algorithm&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Algorithm of Bubble Sorting Method&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Actual code of Bubble sort program in C++ programming language&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
&amp;nbsp;What is Bubble Sort?&lt;/h3&gt;
&lt;b&gt;Bubble sort is a sorting algorithm&lt;/b&gt;, in which we repeatedly pass through the whole array and swap the adjacent elements if they are not sorted. &lt;br /&gt;
&lt;br /&gt;
Note that: &lt;b&gt;In Bubble sort&lt;/b&gt; there will be maximum (n-1) passes to sort the given array. For example, if array size n = 5 then there will be (n-1) that is 4 passes.&lt;br /&gt;
Note that: &lt;b&gt;In first pass&lt;/b&gt; there will be 4 comparisons like 5&amp;gt;4. In second pass there will be 3 comparisons. In third pass there will be two comparisons. And in last that is 4th pass there will be only one comparison.&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Method of Bubble Sorting&lt;/h3&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;1. Compare first two adjacent elements, if first is greater than second then swap them( if&amp;nbsp; sorting on ascending order) &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;2. Repeat this comparison for second and third adjacent elements, then third and fourth elements and so on to second last and last elements. And swap the values where needed. This makes ONE PASS of Bubble Sort Algorithm.&lt;/li&gt;
&lt;li&gt;3. Now again start with first and second element to compare and swap if first is greater than other. This time ignore last element. So you will compare adjacent elements from number 1 to second last element.&lt;/li&gt;
&lt;li&gt;4. Similarly in third pass, you will reduce another comparison from end, and so on.&lt;/li&gt;
&lt;li&gt;5. Keep repeating for one fewer element each time until there will be no pairs to compare. In Last Pass, there will be only one comparison of first and second element.&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Bubble Sort Algorithm and Program Logic in CPP - on Sample Data &lt;/h3&gt;
&lt;h4&gt;
For example:&lt;/h4&gt;
&lt;h4&gt;
Let given un sorted array is:&lt;/h4&gt;
&lt;h4&gt;
5, 4, 3, 2, 1&lt;/h4&gt;
&lt;br /&gt;
&lt;b&gt;In first pass:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;5, 4, 3, 2, 1&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Pass 1:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We will check if 5&amp;gt;4 then swap(5,4) so that array will become as follows&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4, 5, 3, 2, 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check if 5&amp;gt;3 then swap(5,3) so that array will become:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4, 3, 5, 2, 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check if 5&amp;gt;2 then swap(5,2) so that array will become:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4, 3, 2, 5, 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check that if 5&amp;gt;1 then swap(5,1) so that array will become:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; 4, 3, 2, 1, 5&lt;br /&gt;
Note: You should note that in pass 1, the last element (5) is bubbled and placed to its correct location(sorted) in the given array.&lt;br /&gt;
&lt;b&gt;Pass 2:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;4, 3, 2, 1, 5&lt;/b&gt;&lt;br /&gt;
We will check if 4&amp;gt;3 then swap(4,3) which is true , so that array will become as follows:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, 4, 2, 1, 5&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check if 4&amp;gt;2 then swap(4,2) so that array will become:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, 2, 4, 1, 5&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check if 4&amp;gt;1 then swap(4,1) so that array will become:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, 2, 1, 4, 5&lt;br /&gt;
Note:
 You should note that in pass 2, the second last element (4) is bubbled and 
placed to its correct location(sorted) in the given array.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Pass 3: &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;3, 2, 1, 4, 5&lt;/b&gt;&lt;br /&gt;
We will check if 3&amp;gt;2 then swap(3,2) which is true , so that array will become as follows:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, 3, 1, 4, 5&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next we will check if 3&amp;gt;1 then swap(3,1) so that array will become:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, 1, 3, 4, 5&lt;br /&gt;
Note:
 You should note that in pass 3, the third last element (3) is bubbled and 
placed to its correct location(sorted) in the given array.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Pass 4:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;2, 1, 3, 4, 5&lt;/b&gt;&lt;br /&gt;
We will check if 2&amp;gt;1 then swap(2,1) which is true so the array becomes:&lt;br /&gt;
1, 2, 3, 4, 5&lt;br /&gt;
&lt;br /&gt;
Which is the required sorted array. &lt;br /&gt;
&lt;h3&gt;
&amp;nbsp;
Bubble Sort Algorithm and Program Logic in CPP&lt;/h3&gt;
&lt;h3&gt;
Bubble Sort Algorithm&lt;/h3&gt;
&lt;br /&gt;
This algorithm will input values in array A of n size. Then sort the array by Bubble sort method and display the display the array. Suppose A be a linear array of n numbers. Temp is a temporary variable for swapping (interchanging) the position of the numbers in array as required according to the sorting order.&lt;br /&gt;
1. Input n numbers of an array A&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Initialise i=0 and repeat through 1b if (i&amp;lt;n)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 1a) Display Message &quot; Enter a number=&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 1b) Input A[i] &lt;br /&gt;
2. Initialise i= 0 and repeat through step 4 if (i&amp;lt; n)&lt;br /&gt;
3. Initialize j= 0 and repeat through step 4 if (j&amp;lt; n – i– 1)&lt;br /&gt;
4. If (A[j] &amp;gt; A[j + 1])&lt;br /&gt;
(a) Temp = A[j]&lt;br /&gt;
(b) A[j] = A[j + 1]&lt;br /&gt;
(c) A[j+ 1] = Temp&lt;br /&gt;
5. Display the sorted numbers of array A&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;  Initialise i=0 and repeat through 5a if (i&amp;lt;n)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 5a) Display A[i]&lt;br /&gt;
6. Exit.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Picture: Bubble Sort Algorithm and Program Logic in CPP&lt;/u&gt; &lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtNACY-eEnsvPkRosDzWYVml8q4KFahj9cDI1XiXHtQGNUeVRncJzuDM04TotId5E6Ujhw0kA7Djm944NglTvi_0TneL8CycWBwoeq7CLNjid_uOkb_WxLzkWmtVqdN8oQdEH6f9WaIgjs/s1600/Bubble-sort-paper-tracing-data-example-easycppprogramming.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Bubble Sort Algorithm, Trace Steps on Sample data with C++ Program&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtNACY-eEnsvPkRosDzWYVml8q4KFahj9cDI1XiXHtQGNUeVRncJzuDM04TotId5E6Ujhw0kA7Djm944NglTvi_0TneL8CycWBwoeq7CLNjid_uOkb_WxLzkWmtVqdN8oQdEH6f9WaIgjs/s1600/Bubble-sort-paper-tracing-data-example-easycppprogramming.gif&quot; title=&quot;Bubble Sort Algorithm, Trace Steps on Sample data with C++ Program&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Bubble Sort Algorithm, Trace Steps on Sample data with C++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Bubble Sort Program Code for Array of size s = 5 integer elements&lt;/h3&gt;
&lt;h3&gt;
Sample Run in Turbo C++ 3.0 IDE Bubble Sort Algorithm and Program Logic in CPP &lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyC1rEjssOQtiPzSjjtlMInRJZ3QhVsySyEfP0AjwyLlagplnsBDT86qJd51YeK4UtVbN3Si4Oz_SvvhIxOCDEg4OeOOKbtOH5MKXZBUHWL9dRW3esPgsUt7iOIg09dw_S96cnY3rgskm4/s1600/bubble-sort-algorithm-program-logic-in-c-easycppprogramming.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Bubble Sort Algorithm and Program Logic in C++ Trace steps&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyC1rEjssOQtiPzSjjtlMInRJZ3QhVsySyEfP0AjwyLlagplnsBDT86qJd51YeK4UtVbN3Si4Oz_SvvhIxOCDEg4OeOOKbtOH5MKXZBUHWL9dRW3esPgsUt7iOIg09dw_S96cnY3rgskm4/s1600/bubble-sort-algorithm-program-logic-in-c-easycppprogramming.gif&quot; title=&quot;Bubble Sort Algorithm and Program Logic in CPP Trace steps&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Algorithm of Bubble Sort, Tracing Steps on Sample data with C++ Program&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
/*&lt;br /&gt;
(c)EasyCppProgramming.Blogspot.Com&lt;br /&gt;
C++ is Simplified Here!&lt;br /&gt;
Target 1001 C++ Example Programs!&lt;br /&gt;
EasyCppProgramming.Blogspot.Com&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Program To Input an array and sort&lt;br /&gt;
// the array by Bubble Sort Algorithm&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int a[5], s=5, i, j, k, temp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; clrscr();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // input array&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter 5 array elements to sort:\n&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;s;i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;a[i];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // show un-sorted array&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\n Un-Sorted array is =&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;s;i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;a[i]&amp;lt;&amp;lt;&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\n------------------------------------&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // sort array by bubble sort&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;s-1;i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(j=0;j&amp;lt;(s-1-i);j++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(a[j]&amp;gt;a[j+1])&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; temp=a[j];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; a[j]=a[j+1];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; a[j+1]=temp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nAfter Pass &quot;&amp;lt;&amp;lt;(i+1)&amp;lt;&amp;lt;&quot; elements are : &quot;;&lt;br /&gt;
for (k = 0; k &amp;lt; s; k++)&lt;br /&gt;
cout&amp;lt;&amp;lt;a[k]&amp;lt;&amp;lt;&quot;&amp;nbsp;&amp;nbsp; &quot;;&lt;br /&gt;
cout&amp;lt;&amp;lt;endl;&lt;br /&gt;
}/*End of outer for loop*/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // show sorted array&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\n ----------------------------------&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\nSorted Array is = &quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;s;i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;a[i]&amp;lt;&amp;lt;&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // wait for user to press any key&lt;br /&gt;
&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // end&lt;br /&gt;
&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
Now after studying &lt;u&gt;&lt;b&gt;&lt;i&gt;Bubble Sort Algorithm and Program Logic in CPP&lt;/i&gt;&lt;/b&gt;&lt;/u&gt;, Read more on&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/insertion-sort-algorithm-trace-steps.html&quot; target=&quot;_blank&quot;&gt;Insertion Sort Algorithm Trace Steps and Program&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/7597448704879987695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/bubble-sort-algorithm-and-program-logic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7597448704879987695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7597448704879987695'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/bubble-sort-algorithm-and-program-logic.html' title='Bubble Sort Algorithm Trace Steps on Sample Data and C++ Program'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtNACY-eEnsvPkRosDzWYVml8q4KFahj9cDI1XiXHtQGNUeVRncJzuDM04TotId5E6Ujhw0kA7Djm944NglTvi_0TneL8CycWBwoeq7CLNjid_uOkb_WxLzkWmtVqdN8oQdEH6f9WaIgjs/s72-c/Bubble-sort-paper-tracing-data-example-easycppprogramming.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6041963998265017539</id><published>2014-01-14T09:13:00.001+05:00</published><updated>2018-05-19T23:19:01.343+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Do While ~ For ~While loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Explain Different Types of Iterative Looping Structures"/><title type='text'>Explain Different Types of Iterative Looping Structures</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;
What is a Looping Structure in C++?&lt;/h3&gt;
&lt;br /&gt;
A looping structure is a statement used to repeatedly execute a block of&amp;nbsp; one or more statements for a specified number of times or as long as a given condition remains true. &lt;br /&gt;
&lt;br /&gt;
In C++, looping statements are also called Repetitive statements or Iterative Statements.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Different Types of&amp;nbsp; Looping Structures in C++&lt;/h3&gt;
&lt;br /&gt;
There are &lt;b&gt;three types of looping structures in C and C++&lt;/b&gt; programming languages, as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html&quot;&gt;for loop&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot;&gt;while loop&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html&quot;&gt;do while loop&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9PHFIj_k-Z-bIK0UILdcv80Xwj4n4KrKx0Lbex4HYZWWS80M8JLtpIYF9d2lLqnZvbVa4xy_zxqy2fmRhVBPQ7_RB0CnKIOdzaFw0YlsKF8JvBDdF26ukKqkfx4jPrAUPI1Z9-KW9OGw7/s1600/explain-different-types-of-loops-in-c.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Explain Different Types of Iterative Looping Structures&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9PHFIj_k-Z-bIK0UILdcv80Xwj4n4KrKx0Lbex4HYZWWS80M8JLtpIYF9d2lLqnZvbVa4xy_zxqy2fmRhVBPQ7_RB0CnKIOdzaFw0YlsKF8JvBDdF26ukKqkfx4jPrAUPI1Z9-KW9OGw7/s1600/explain-different-types-of-loops-in-c.jpg&quot; title=&quot;Explain Different Types of Iterative Looping Structures&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;Let us study these iterative statements deeply with syntax and purpose with the help of sample codes and outputs.&lt;br /&gt;
&lt;div&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-2597697146450859&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;9955918948&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
1. &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html&quot;&gt;for Loop statement&lt;/a&gt;&lt;/h3&gt;
&lt;br /&gt;
A &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html&quot;&gt;for loop statement&lt;/a&gt; is used to execute a block of one or more statements repeatedly for a specified number of times.&lt;br /&gt;
&lt;h3&gt;
Syntax of for loop&lt;/h3&gt;
&lt;br /&gt;
for(initialization;condition;increment/decrement-expression)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement 2;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp; statement N; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Example of for loop&lt;/h3&gt;
&lt;br /&gt;
int d;&lt;br /&gt;
for(d=5; d&amp;gt;=1; d--)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;d&amp;lt;&amp;lt;endl; &lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
5&lt;br /&gt;
4&lt;br /&gt;
3&lt;br /&gt;
2&lt;br /&gt;
1&lt;br /&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
2. while Loop Statement in C / C++&lt;/h3&gt;
&lt;br /&gt;
while loop is used to execute a block of one or more statements repeatedly as long as the given condition remains true.&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;
Syntax of while loop&lt;/h3&gt;
&lt;br /&gt;
while(condition)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement 2;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp; statement N; &lt;br /&gt;
} &lt;br /&gt;
&lt;h3&gt;
Example of while loop&lt;/h3&gt;
&lt;br /&gt;
int f=5;&lt;br /&gt;
while(f&amp;gt;=1)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;f&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; f--;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Output:&lt;/h3&gt;
5&lt;br /&gt;
4&lt;br /&gt;
3&lt;br /&gt;
2&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
3. do while Loop statement in C / C++&lt;/h3&gt;
&lt;br /&gt;
A &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html&quot;&gt;do while loop&lt;/a&gt; is used to execute a block of one or more statements as long as the given condition remains true but condition is placed after loop body.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Syntax of do while loop&lt;/h3&gt;
&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; statement 2;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;br /&gt;
&amp;nbsp;&amp;nbsp; statement N; &lt;br /&gt;
}&lt;br /&gt;
while(condition);&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html&quot;&gt;Example of do while loop&lt;/a&gt;&lt;/h3&gt;
&lt;br /&gt;
int h=5; &lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;h&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; h--;&lt;br /&gt;
}&lt;br /&gt;
while(h&amp;gt;=1);&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Output:&lt;/h3&gt;
&lt;br /&gt;
5&lt;br /&gt;
4&lt;br /&gt;
3&lt;br /&gt;
2&lt;br /&gt;
1&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html&quot; target=&quot;_blank&quot;&gt;http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
After studying a brief description of &lt;u&gt;&lt;b&gt;Different Types of Iterative Looping Structures in C++&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;b&gt;For further reading:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/u&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html&quot; target=&quot;_blank&quot;&gt;Purpose and Example of do while Loop in CPP Language&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-2597697146450859&quot;
     data-ad-slot=&quot;9955918948&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot; target=&quot;_blank&quot;&gt;Working of for loop statement with examples&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot; target=&quot;_blank&quot;&gt;Working of While Loop With Examples&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6041963998265017539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/explain-different-types-of-iterative.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6041963998265017539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6041963998265017539'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/explain-different-types-of-iterative.html' title='Explain Different Types of Iterative Looping Structures'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9PHFIj_k-Z-bIK0UILdcv80Xwj4n4KrKx0Lbex4HYZWWS80M8JLtpIYF9d2lLqnZvbVa4xy_zxqy2fmRhVBPQ7_RB0CnKIOdzaFw0YlsKF8JvBDdF26ukKqkfx4jPrAUPI1Z9-KW9OGw7/s72-c/explain-different-types-of-loops-in-c.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-7210735945986850095</id><published>2014-01-13T22:48:00.000+05:00</published><updated>2018-03-16T06:43:35.799+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Do while loop flow chart example"/><category scheme="http://www.blogger.com/atom/ns#" term="do while loop with program examples in C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Easy C++ tutorial on do while loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Easy Explaination of DO While loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Use of Do While loop in C++ Programs"/><title type='text'>Purpose and Example of do while Loop in CPP Language</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;
What is a do while Loop?&lt;/h3&gt;
The &lt;b&gt;do while&lt;/b&gt; loop is another &lt;b&gt;iterative statement&lt;/b&gt; in &lt;b&gt;C++ language&lt;/b&gt;. It is used to repeat a set of one or more statements while the given condition remains true. It is similar to &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot;&gt;&lt;b&gt;while loop&lt;/b&gt;&lt;/a&gt; in C++ except that the condition is written after the body of loop.&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUZhShg1BdQnhkRcBfmkt9_-EwGf2wWMCCmwrJgdvbg5F_opvcF4OA66yLAsivC5mxXehGbgfHE0ExZIi9S_q568QJx0yo_aS4MfsKm_lnqB_RK_JLq0NpuH-jFkYf0edVJyIG1ZummHS1/s1600/purpose-example-working-do-while-loop-in-c.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Purpose and Example of do while Loop in CPP Language&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUZhShg1BdQnhkRcBfmkt9_-EwGf2wWMCCmwrJgdvbg5F_opvcF4OA66yLAsivC5mxXehGbgfHE0ExZIi9S_q568QJx0yo_aS4MfsKm_lnqB_RK_JLq0NpuH-jFkYf0edVJyIG1ZummHS1/s1600/purpose-example-working-do-while-loop-in-c.jpg&quot; title=&quot;Purpose and Example of do while Loop in CPP Language&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Purpose and Example of do while Loop in C++ Language&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3&gt;
Syntax of do while loop&lt;/h3&gt;
&lt;br /&gt;
&lt;b&gt;do&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement 1;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement 2;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement N;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;while (condition);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
do is a reserved word or keyword.&lt;br /&gt;
&lt;b&gt;{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement 1;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement 2;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; .&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; statement N;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
is body of loop (a set of one or more statements enclosed in curly brackets)&lt;br /&gt;
&lt;b&gt;while &lt;/b&gt;is a reserved word or keyword&lt;br /&gt;
&lt;b&gt;condition &lt;/b&gt;is normally given as a relational expression like (n&amp;gt;=1) etc&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Example of do while loop&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;int n = 1;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;do&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;n&amp;lt;&amp;lt;endl;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n++;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;}&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;while (n&amp;lt;=5);&amp;nbsp; &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Output of the above written C++ code segment is list of 1 to 5 numbers as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;5&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
How this output comes? &lt;/h3&gt;
1. First of all an integer variable n is intialized to 1.&lt;br /&gt;
2. Body of loop is executed for first time. &lt;span style=&quot;color: blue;&quot;&gt;1&lt;/span&gt; is printed and control goes to next line due to &lt;b&gt;endl&lt;/b&gt;.&lt;br /&gt;
3. The valuse of n is incremented by one so that n is equal to 2 now.&lt;br /&gt;
4. Condition is checked for first time n&amp;lt;=5, that is, 2&amp;lt;=5 which is true.&lt;br /&gt;
5. Body of loop is executed for second time.&lt;br /&gt;
6. &lt;span style=&quot;color: blue;&quot;&gt;2&lt;/span&gt; is printed and control goes to next line due to &lt;b&gt;endl&lt;/b&gt;.&lt;br /&gt;
7. The value of n is incremented by one so that n is equal to 3 now.&lt;br /&gt;
8. Condition is checked&amp;nbsp; n&amp;lt;=5, that is, 3&amp;lt;=5 which is true.&lt;br /&gt;
9. Body of loop is executed for third time.&lt;br /&gt;
6. &lt;span style=&quot;color: blue;&quot;&gt;3&lt;/span&gt; is printed and control goes to next line due to &lt;b&gt;endl&lt;/b&gt;.&lt;br /&gt;
7. The value of n is incremented by one so that n is equal to 4 now.&lt;br /&gt;
8. Condition is checked&amp;nbsp; n&amp;lt;=5, that is, 4&amp;lt;=5 which is true.&lt;br /&gt;
9. Body of loop is executed for fourth time.&lt;br /&gt;
10. &lt;span style=&quot;color: blue;&quot;&gt;4&lt;/span&gt; is printed and control goes to next line due to &lt;b&gt;endl&lt;/b&gt;.&lt;br /&gt;
11. The value of n is incremented by one so that n is equal to 5 now.&lt;br /&gt;
12. Condition is checked&amp;nbsp; n&amp;lt;=5, that is, 5&amp;lt;=5 which is true.&lt;br /&gt;
13. Body of loop is executed for fourth time.&lt;br /&gt;
14. &lt;span style=&quot;color: blue;&quot;&gt;5&lt;/span&gt; is printed and control goes to next line due to &lt;b&gt;endl&lt;/b&gt;.&lt;br /&gt;
15. The value of n is incremented by one so that n is equal to 6 now.&lt;br /&gt;
16. Condition is checked&amp;nbsp; n&amp;lt;=5, that is, 6&amp;lt;=5 which is false. So the do while loop ends here.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Example 2 of do while loop&lt;/h3&gt;
&lt;br /&gt;
int n=100;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;n&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; n++;&lt;br /&gt;
}&lt;br /&gt;
while (n&amp;gt;=1000);&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Output is as follows:&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;100 &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Explanation of working of above sample do while code:&lt;/h3&gt;
1. First of all the value of n is set to 100.&lt;br /&gt;
2. Body of loop is executed for the first time.&lt;br /&gt;
3. 100 is printed on screen and control goes to next line due to endl. The value of variable n is incremented by one so that now n = 101&lt;br /&gt;
4. The given condition (n&amp;gt;=1000) is checked. Since the condition (101&amp;gt;=1000) is false so the loop will will end.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/7210735945986850095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7210735945986850095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/7210735945986850095'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/purpose-and-example-of-do-while-loop-in.html' title='Purpose and Example of do while Loop in CPP Language'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUZhShg1BdQnhkRcBfmkt9_-EwGf2wWMCCmwrJgdvbg5F_opvcF4OA66yLAsivC5mxXehGbgfHE0ExZIi9S_q568QJx0yo_aS4MfsKm_lnqB_RK_JLq0NpuH-jFkYf0edVJyIG1ZummHS1/s72-c/purpose-example-working-do-while-loop-in-c.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-6771593448330873311</id><published>2014-01-10T17:22:00.003+05:00</published><updated>2018-03-17T19:23:46.424+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Display N Fibonacci Terms in C C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Explanation of Fibonacci Series n Terms Program"/><category scheme="http://www.blogger.com/atom/ns#" term="Fibonacci c programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Fibonacci c++ program logic"/><category scheme="http://www.blogger.com/atom/ns#" term="Fibonacci program"/><category scheme="http://www.blogger.com/atom/ns#" term="Show N Fibonacci Terms Program Sample"/><title type='text'>Explanation of Fibonacci Series n Terms Program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Q:Write a C++ program to input a number N and display N fibonacci Terms.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Program Planning: Printing n Terms of Fibonacci Series&lt;/h2&gt;
We start the logic building about the above mentioned Fibonacci series program. First of all we try to understand what the Fibonacci Series is:&lt;br /&gt;
&lt;h3&gt;
What is a Fibonacci Series?&lt;/h3&gt;
Fibonacci Series is a series of numbers where every next number is obtained by adding the two previous numbers. Note that first two numbers are 0 and 1 by definition. So the Fibonacci Series will be as under:&lt;br /&gt;
&lt;h4&gt;
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 and so on.&lt;/h4&gt;
&lt;h4&gt;
&lt;/h4&gt;
&lt;table border=&quot;1&quot; style=&quot;width: 51%px;&quot;&gt;
  &lt;tbody&gt;
&lt;tr&gt;
    &lt;td width=&quot;10%&quot;&gt;Term No&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;1&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;2&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;3&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;4&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;5&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;6&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;7&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;8&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;9&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;10&lt;/td&gt;
  &lt;/tr&gt;
&lt;tr&gt;
    &lt;td width=&quot;10%&quot;&gt;Term&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;0&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;1&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;1&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;2&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;3&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;5&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;8&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;13&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;21&lt;/td&gt;
    &lt;td width=&quot;10%&quot;&gt;34&lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
For example, if we wish to write Nth term of the series, then we will get nth term by adding (n-1)th and (n-2)th term.&lt;br /&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Nth Term = (n-1)th Term + (n&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;-2)th Term&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;For example, if we wish to find 5th term&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;5th Term&amp;nbsp; = (5-1)th + (5-2)th Term&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 2 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; + &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 3&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlM_YrWbXrose6W8oeVz9ymqLe-rSnHQ_MbdtRtKIxf54gPwJwQ2zTuo0_Le5Riei0Wqeff7GZylNztiynKOLEMe1yar4PxvF_sx9I-GThNsF8jy-Xcl9G-F29oJ10fkIUkcTOCJSZR2KO/s1600/display-n-terms-fibonacci-series-logic-easy.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway how to write C++ Program Logic: N Terms of Fibonacci Series in C++&quot; border=&quot;0&quot; height=&quot;211&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlM_YrWbXrose6W8oeVz9ymqLe-rSnHQ_MbdtRtKIxf54gPwJwQ2zTuo0_Le5Riei0Wqeff7GZylNztiynKOLEMe1yar4PxvF_sx9I-GThNsF8jy-Xcl9G-F29oJ10fkIUkcTOCJSZR2KO/s1600/display-n-terms-fibonacci-series-logic-easy.gif&quot; title=&quot;Easyway how to write C++ Program Logic: N Terms of Fibonacci Series in C++&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;h3&gt;
Easyway how to write C++ Program Logic: N Terms of Fibonacci Series in C++&lt;/h3&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h4&gt;
&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;
&lt;h3&gt;
Program Logic: N Terms of Fibonacci Series in C++&lt;/h3&gt;
1. We know that First Two Terms are 0 and 1, so initialize First=0 and Second=1&lt;br /&gt;
2. Print the value of first and second term by cout&amp;lt;&amp;lt;&lt;br /&gt;
3. If we find n terms then we know that we have already displayed two terms. Therefore, we will use a while loop to display remaining n-2 terms. In loop body we will add first and second to get third term.&lt;br /&gt;
4. Now we will place the value of second term in first. We will also place value of&amp;nbsp; third term in second.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Program Coding: N Terms of Fibonacci Series in C++&lt;/h3&gt;
/*&lt;br /&gt;
(c)EasyCppProgramming.Blogspot.Com&lt;br /&gt;
C++ is Simplified Here!&lt;br /&gt;
Target 1001 C++ Example Programs!&lt;br /&gt;
EasyCppProgramming.Blogspot.Com&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Program To Input a Number n and&lt;br /&gt;
// display n terms of Fibonacci Series&lt;br /&gt;
// by while loop&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;int main()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int first=0, second=1, third, count=2, n;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; clrscr();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;How Many Terms of Fibonacci Series? &quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; if (n&amp;lt;1)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\n Invalid Input, Enter a Positive number&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(0);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; if (n==1)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;first;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; else if (n==2)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;first&amp;lt;&amp;lt;&quot;\t&quot;&amp;lt;&amp;lt;second;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; else&lt;br /&gt;
&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;first&amp;lt;&amp;lt;&quot;\t&quot;&amp;lt;&amp;lt;second;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(count&amp;lt;n)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; third = first + second;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;\t&quot;&amp;lt;&amp;lt;third;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; first = second;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; second = third;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count++;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
Further reading suggestions:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/basic-structure-of-c-progra.html&quot; target=&quot;_blank&quot;&gt;Basic Structure of a C++ Program&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/c-program-development-cycle.html&quot; target=&quot;_blank&quot;&gt;C++ Program Development Cycle&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/how-to-write-compile-and-run-your-first.html&quot; target=&quot;_blank&quot;&gt;How To Write, Compile and Run Your First C++ Program&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/how-to-install-turbo-c-30-ide.html&quot; target=&quot;_blank&quot;&gt;How To Start Turbo C++ IDE&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/how-to-install-turbo-c-30-ide.html&quot; target=&quot;_blank&quot;&gt;How To Install Turbo C++ 3.0 - IDE&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/features-of-c-programming-language.html&quot; target=&quot;_blank&quot;&gt;Features of C++ Programming Language&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/brief-history-of-c.html&quot; target=&quot;_blank&quot;&gt;Brief History of C++&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/flowcharts-in-computer-programming.html&quot; target=&quot;_blank&quot;&gt;Flowcharts in Computer Programming&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/role-of-algorithms-in-programming.html&quot; target=&quot;_blank&quot;&gt;The Role of Algorithms in Programming&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/how-to-start-computer-programming.html&quot; target=&quot;_blank&quot;&gt;How To Start Computer Programming&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://easycppprogramming.blogspot.com/2011/07/what-is-computer-program.html&quot; target=&quot;_blank&quot;&gt;What is a Computer Program&lt;/a&gt;&lt;br /&gt;
- See more at: &lt;a href=&quot;http://easycppprogramming.blogspot.com/&quot;&gt;http://easycppprogramming.blogspot.com&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/6771593448330873311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/explanation-of-fibonacci-series-n-terms.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6771593448330873311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/6771593448330873311'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/explanation-of-fibonacci-series-n-terms.html' title='Explanation of Fibonacci Series n Terms Program'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlM_YrWbXrose6W8oeVz9ymqLe-rSnHQ_MbdtRtKIxf54gPwJwQ2zTuo0_Le5Riei0Wqeff7GZylNztiynKOLEMe1yar4PxvF_sx9I-GThNsF8jy-Xcl9G-F29oJ10fkIUkcTOCJSZR2KO/s72-c/display-n-terms-fibonacci-series-logic-easy.gif" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8506354445069520893.post-1117821381014965233</id><published>2014-01-10T14:07:00.002+05:00</published><updated>2018-03-17T19:52:32.133+05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Program Factorial by While Loop Logic"/><title type='text'>Program Factorial by While Loop Logic</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4&gt;
Q: Write a program in C++ to input a number and display its factorial. &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot;&gt;Use while Loop&lt;/a&gt;.&lt;/h4&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJwAFD-Fj1RHQJ9PHjIwl_xUuKjcdACjJLokk9zJoP598ePkYCxxpzno3aCtiNG-QVMVaqv1nZ68TrcB0KS9xghbYhFhqnzvsZfWTQ9tYLhhyphenhyphenL8sNUB6CcRDNIV4H2CxRLxZQ2ZY4txQYJ/s1600/c_plus_plus_program_factorial_number.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Easyway How to Write a program in C++ to input a number and display its factorial&quot; border=&quot;0&quot; data-original-height=&quot;354&quot; data-original-width=&quot;447&quot; height=&quot;253&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJwAFD-Fj1RHQJ9PHjIwl_xUuKjcdACjJLokk9zJoP598ePkYCxxpzno3aCtiNG-QVMVaqv1nZ68TrcB0KS9xghbYhFhqnzvsZfWTQ9tYLhhyphenhyphenL8sNUB6CcRDNIV4H2CxRLxZQ2ZY4txQYJ/s320/c_plus_plus_program_factorial_number.jpg&quot; title=&quot;Easyway How to Write a program in C++ to input a number and display its factorial&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;h4&gt;
Easyway How to Write a program in C++ to input a number and display its factorial&lt;/h4&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3&gt;
Program factorial : How to understand mathematical&amp;nbsp; Logic behind factorial? &lt;/h3&gt;
We know that factorial of a number is equal to the product of all numbers from one to the given number. For example&lt;br /&gt;
Factorial of&amp;nbsp; 3 = 1 x 2 x 3&amp;nbsp;&amp;nbsp; hence 6&lt;br /&gt;
Factorial of&amp;nbsp; 4 = 1 x 2 x 3 x 4 , hence 24&lt;br /&gt;
Similarly Factorial of&amp;nbsp; N = 1 x 2 x 3 .......... x n&lt;br /&gt;
If&amp;nbsp; N = 5 then&lt;br /&gt;
Factorial = 1 x 2 x 3 x 4 x 5 , hence 125&lt;br /&gt;
Which Statements we Need For Factorial Program?&lt;br /&gt;
1. We need cout&amp;lt;&amp;lt; for displaying messages and results to the user.&lt;br /&gt;
2. We need cin&amp;gt;&amp;gt; for inputting a number.&lt;br /&gt;
3. We need assignment statement, for example fact = 1;&lt;br /&gt;
4. We need a &lt;a href=&quot;http://easycppprogramming.blogspot.com/2014/01/working-of-while-loop-with-examples.html&quot;&gt;while loop statement&lt;/a&gt; to multiply all numbers from 1 to N.&lt;br /&gt;
And above all we need some &lt;a href=&quot;http://easycppprogramming.blogspot.com/search/label/C%2B%2B%20Variables%20declaration&quot;&gt;variable declarations&lt;/a&gt; as well.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Coding : Find Factorial of a Number by while Loop&lt;/h3&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;/*&lt;br /&gt;(c)EasyCppProgramming.Blogspot.Com&lt;br /&gt;C++ is Simplified Here!&lt;br /&gt;Target 1001 C++ Example Programs!&lt;br /&gt;EasyCppProgramming.Blogspot.Com&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// Program To Input a Number and Find&lt;br /&gt;// its Factorial by while Loop&lt;br /&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;int main()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; int num;&lt;br /&gt;&amp;nbsp;&amp;nbsp; clrscr();&lt;br /&gt;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter a Number to Display\nits Factorial=&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;num;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; long i=1, fact=1;&lt;br /&gt;&amp;nbsp;&amp;nbsp; while(i&amp;lt;=num)&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; fact = fact * i;&lt;br /&gt;&amp;nbsp;&amp;nbsp; i++;&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Factorial of &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot; = &quot;&amp;lt;&amp;lt;fact&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp; getch();&lt;br /&gt;&amp;nbsp;&amp;nbsp; return 0;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&amp;nbsp;A Sample Run on Paper of Program Factorial&lt;/h3&gt;
1.&amp;nbsp; Let we input 3.&lt;br /&gt;
2. Now num = 3, we also initialize i and fact variables to 1.So that now i = 1 and fact =1&lt;br /&gt;
3. Condition of While loop is tested (i&amp;lt;=num) putting the values 1&amp;lt;=3 which is true.&lt;br /&gt;
4. So while loop starts &lt;br /&gt;
&lt;h3&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; First Iteration&lt;/h3&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fact = fact * i&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; before execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; =&amp;nbsp; 1 &amp;nbsp;&amp;nbsp; * &amp;nbsp; 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; fact =1 and i = 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; fact =1&amp;nbsp; and i =1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The value of i is incremented by 1 so i=2&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;h3&gt;
Second Iteration&lt;/h3&gt;
Since i&amp;lt;=num that is 2&amp;lt;=3 is true so loop takes second iteration &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fact = fact * i&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; before execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; =&amp;nbsp; 1 &amp;nbsp;&amp;nbsp; * &amp;nbsp; 2&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; fact =1 and i = 2&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after execution&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fact =2&amp;nbsp; and i =2&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note: First of all, Right hand side expression (1 * 2) is evaluated and the result is assigned to the variable fact on left hand side of&amp;nbsp; =. &lt;br /&gt;
The value of i is incremented by 1 so i=3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Third Iteration&lt;/h3&gt;
Since i&amp;lt;=num that is 3&amp;lt;=3 is true so loop takes third iteration &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fact = fact * i&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; before execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; =&amp;nbsp; 2 &amp;nbsp;&amp;nbsp; * &amp;nbsp; 3&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; fact =2 and i = 3&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; fact =6&amp;nbsp; and i =3&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The value of i is incremented by 1 so i=4&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Since i&amp;lt;=num that is 4&amp;lt;=3 is false so loop ends now.&lt;br /&gt;
&lt;br /&gt;
The control goes to next statement which is&lt;br /&gt;
&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt; cout&amp;lt;&amp;lt;&quot;Factorial of &quot;&amp;lt;&amp;lt;num&amp;lt;&amp;lt;&quot; = &quot;&amp;lt;&amp;lt;fact&amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;S&lt;/b&gt;o it will print &lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;Factorial of 3 = 6&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://easycppprogramming.blogspot.com/feeds/1117821381014965233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/program-factorial-by-while-loop-logic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1117821381014965233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8506354445069520893/posts/default/1117821381014965233'/><link rel='alternate' type='text/html' href='http://easycppprogramming.blogspot.com/2014/01/program-factorial-by-while-loop-logic.html' title='Program Factorial by While Loop Logic'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJwAFD-Fj1RHQJ9PHjIwl_xUuKjcdACjJLokk9zJoP598ePkYCxxpzno3aCtiNG-QVMVaqv1nZ68TrcB0KS9xghbYhFhqnzvsZfWTQ9tYLhhyphenhyphenL8sNUB6CcRDNIV4H2CxRLxZQ2ZY4txQYJ/s72-c/c_plus_plus_program_factorial_number.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>