{"id":48292,"date":"2021-10-28T12:44:21","date_gmt":"2021-10-28T07:14:21","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/"},"modified":"2026-07-30T15:49:20","modified_gmt":"2026-07-30T10:19:20","slug":"simple-c-programs","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/","title":{"rendered":"Simple C++ Programs"},"content":{"rendered":"\n<p id=\"h-\">Learning <a href=\"https:\/\/www.mygreatlearning.com\/blog\/c-tutorial\/\">C++<\/a> isn't about memorizing syntax\u2014it's about solving problems. The best way to master the language is by writing small, practical programs that introduce one concept at a time.<\/p>\n\n\n\n<p>Whether you're a computer science student preparing for coding interviews or just starting your programming journey, practicing beginner-friendly C++ programs helps you build a strong foundation before moving on to advanced topics like object-oriented programming, data structures, and algorithms.<\/p>\n\n\n\n<p>In this guide, you'll find carefully selected C++ programs that cover the fundamentals of programming. Each example includes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Complete C++ source code<\/li>\n\n\n\n<li>Sample output<\/li>\n\n\n\n<li>Step-by-step explanation<\/li>\n\n\n\n<li>Time and space complexity<\/li>\n\n\n\n<li>Common beginner mistakes<\/li>\n\n\n\n<li>Key concepts you'll learn<\/li>\n<\/ul>\n\n\n\n<p>By the end of this tutorial, you'll understand how to work with variables, input\/output streams, arithmetic operators, conditional statements, and built-in operators such as <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00d084\" class=\"has-inline-color\">sizeof()<\/mark>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"what-are-simple-c-programs\"><strong>What Are Simple C++ Programs?<\/strong><\/h1>\n\n\n\n<p>Simple C++ programs are beginner-level coding exercises designed to teach core programming concepts. They focus on basic syntax, user input, variables, operators, conditions, loops, and functions.<\/p>\n\n\n\n<p>These programs help beginners:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand C++ syntax<\/li>\n\n\n\n<li>Develop logical thinking<\/li>\n\n\n\n<li>Learn problem-solving<\/li>\n\n\n\n<li>Prepare for coding interviews<\/li>\n\n\n\n<li>Build confidence before working on projects<\/li>\n<\/ul>\n\n\n\n<p>Looking to build your C++ skills further? Explore the <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\">C++ Programming for Beginners to Advanced course by Great Learning Academy Pro<\/a> to master core concepts, object-oriented programming, pointers, memory management, and hands-on projects.\u00a0<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"why-should-beginners-practice-c-programs\"><strong>Why Should Beginners Practice C++ Programs?<\/strong><\/h1>\n\n\n\n<p>Every experienced programmer started with small coding exercises.<\/p>\n\n\n\n<p>Writing simple programs helps you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Learn faster through practice<\/li>\n\n\n\n<li>Understand compiler errors<\/li>\n\n\n\n<li>Improve debugging skills<\/li>\n\n\n\n<li>Build programming logic<\/li>\n\n\n\n<li>Gain confidence before solving complex problems<\/li>\n<\/ul>\n\n\n\n<p>Instead of reading theory for hours, writing code every day is the fastest way to improve.<\/p>\n\n\n\n<p><strong>Prerequisites<\/strong><\/p>\n\n\n\n<p>Before starting these examples, make sure you know:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>How to install a C++ compiler<\/li>\n\n\n\n<li>How to create a C++ source file<\/li>\n\n\n\n<li>Basic understanding of variables<\/li>\n\n\n\n<li>How to run a C++ program<\/li>\n<\/ul>\n\n\n\n<p>If you're completely new, don't worry\u2014every example below explains each concept step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-1-hello-world-in-c\"><strong>Program 1: Hello World in C++<\/strong><\/h2>\n\n\n\n<p>The \"Hello World\" program is traditionally the first program every programmer writes. It introduces the basic structure of a C++ program and demonstrates how to display output on the console.<\/p>\n\n\n\n<p id=\"h-c-code\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be29795\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nint main() {\n    std::cout &lt;&lt; &quot;Hello, World!&quot;;\n    return 0;\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297a0\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Hello, World!<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-how-it-works\"><strong>How It Works<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00d084\" class=\"has-inline-color\">#include &lt;iostream><\/mark> imports the input\/output library.<\/li>\n\n\n\n<li>main() is the starting point of every C++ program.<\/li>\n\n\n\n<li>std::cout prints text on the console.<\/li>\n\n\n\n<li>return 0; tells the operating system that the program finished successfully.<\/li>\n<\/ul>\n\n\n\n<p id=\"h-time-complexity\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-common-mistakes\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting the semicolon.<\/li>\n\n\n\n<li>Missing the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00d084\" class=\"has-inline-color\">#include &lt;iostream><\/mark> header.<\/li>\n\n\n\n<li>Writing cout without <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00d084\" class=\"has-inline-color\">std::<\/mark> when not using the std namespace.<\/li>\n<\/ul>\n\n\n\n<p id=\"h-key-concepts\"><strong>Key Concepts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Program structure<\/li>\n\n\n\n<li>Header files<\/li>\n\n\n\n<li>main() function<\/li>\n\n\n\n<li>cout<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-2-print-user-input\"><strong>Program 2: Print User Input<\/strong><\/h2>\n\n\n\n<p>Accepting user input is one of the first interactive features you'll learn in C++. This program reads an integer from the keyboard and displays it back to the user.<\/p>\n\n\n\n<p id=\"h-c-code-0\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297b5\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    int number;\n\n    cout &lt;&lt; &quot;Enter a number: &quot;;\n    cin &gt;&gt; number;\n\n    cout &lt;&lt; &quot;You entered: &quot; &lt;&lt; number;\n\n    return 0;\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-0\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297bc\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter a number: 25\n\nYou entered: 25<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-how-it-works-0\"><strong>How It Works<\/strong><\/p>\n\n\n\n<p>The cin object reads input from the keyboard and stores it in the variable number. The cout object then displays the stored value.<\/p>\n\n\n\n<p id=\"h-time-complexity-0\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-0\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-common-mistakes-0\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using the wrong data type.<\/li>\n\n\n\n<li>Forgetting cin >>.<\/li>\n\n\n\n<li>Declaring variables after using them.<\/li>\n<\/ul>\n\n\n\n<p id=\"h-what-you-ll-learn\"><strong>What You'll Learn<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables<\/li>\n\n\n\n<li>User input<\/li>\n\n\n\n<li>Output<\/li>\n\n\n\n<li>Integer data type<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-3-add-two-numbers\"><strong>Program 3: Add Two Numbers<\/strong><\/h2>\n\n\n\n<p>Adding two numbers is one of the simplest ways to understand arithmetic operators and user input.<\/p>\n\n\n\n<p id=\"h-c-code-1\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297ce\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n\n    int a, b;\n\n    cout &lt;&lt; &quot;Enter two numbers: &quot;;\n    cin &gt;&gt; a &gt;&gt; b;\n\n    cout &lt;&lt; &quot;Sum = &quot; &lt;&lt; a + b;\n\n    return 0;\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-1\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297d3\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter two numbers: 15 20\n\nSum = 35<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-explanation\"><strong>Explanation<\/strong><\/p>\n\n\n\n<p>The program accepts two integers from the user and uses the + operator to calculate their sum.<\/p>\n\n\n\n<p id=\"h-complexity\"><strong>Complexity<\/strong><\/p>\n\n\n\n<p>Time: <strong>O(1)<\/strong><\/p>\n\n\n\n<p>Space: <strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-concepts-covered\"><strong>Concepts Covered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arithmetic operators<\/li>\n\n\n\n<li>Multiple user inputs<\/li>\n\n\n\n<li>Integer addition<\/li>\n<\/ul>\n\n\n\n<p id=\"h-beginner-tip\"><strong>Beginner Tip<\/strong><\/p>\n\n\n\n<p>Always initialize variables before using them in calculations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-4-find-quotient-and-remainder\"><strong>Program 4: Find Quotient and Remainder<\/strong><\/h2>\n\n\n\n<p>Division in C++ produces two useful values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Quotient<\/li>\n\n\n\n<li>Remainder<\/li>\n<\/ul>\n\n\n\n<p>The modulus (%) operator returns the remainder after division.<\/p>\n\n\n\n<p id=\"h-c-code-2\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297eb\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int dividend, divisor;\n\n    cout &lt;&lt; &quot;Enter dividend: &quot;;\n\n    cin &gt;&gt; dividend;\n\n    cout &lt;&lt; &quot;Enter divisor: &quot;;\n\n    cin &gt;&gt; divisor;\n\n    cout &lt;&lt; &quot;Quotient = &quot; &lt;&lt; dividend \/ divisor &lt;&lt; endl;\n\n    cout &lt;&lt; &quot;Remainder = &quot; &lt;&lt; dividend % divisor;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-sample-output\"><strong>Sample Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be297f0\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter dividend: 15\n\nEnter divisor: 2\n\nQuotient = 7\n\nRemainder = 1<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-how-it-works-1\"><strong>How It Works<\/strong><\/p>\n\n\n\n<p>The \/ operator performs integer division, while % calculates the remainder.<\/p>\n\n\n\n<p id=\"h-time-complexity-1\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-1\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-common-mistakes-1\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Dividing by zero.<\/li>\n\n\n\n<li>Using % with floating-point numbers.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-5-find-the-size-of-data-types\"><strong>Program 5: Find the Size of Data Types<\/strong><\/h2>\n\n\n\n<p>Different data types occupy different amounts of memory. C++ provides the sizeof() operator to determine how much memory a data type or variable uses.<\/p>\n\n\n\n<p id=\"h-c-code-3\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be2980b\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    cout &lt;&lt; &quot;int: &quot; &lt;&lt; sizeof(int) &lt;&lt; &quot; bytes\\n&quot;;\n\n    cout &lt;&lt; &quot;float: &quot; &lt;&lt; sizeof(float) &lt;&lt; &quot; bytes\\n&quot;;\n\n    cout &lt;&lt; &quot;char: &quot; &lt;&lt; sizeof(char) &lt;&lt; &quot; byte\\n&quot;;\n\n    cout &lt;&lt; &quot;double: &quot; &lt;&lt; sizeof(double) &lt;&lt; &quot; bytes&quot;;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-2\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be29810\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>int: 4 bytes\n\nfloat: 4 bytes\n\nchar: 1 byte\n\ndouble: 8 bytes<\/code><\/pre><\/div>\n\n\n\n<p><strong>Note:<\/strong> Exact sizes may vary by compiler and system architecture, though the values above are common on modern platforms.<\/p>\n\n\n\n<p id=\"h-why-this-program-matters\"><strong>Why This Program Matters<\/strong><\/p>\n\n\n\n<p>Understanding memory usage is essential for writing efficient C++ programs. The sizeof() operator is also widely used in arrays, structures, templates, and systems programming.<\/p>\n\n\n\n<p id=\"h-complexity-0\"><strong>Complexity<\/strong><\/p>\n\n\n\n<p>Time: <strong>O(1)<\/strong><\/p>\n\n\n\n<p>Space: <strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-concepts-covered-0\"><strong>Concepts Covered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data types<\/li>\n\n\n\n<li>Memory allocation<\/li>\n\n\n\n<li>sizeof() operator<\/li>\n\n\n\n<li>Console output<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"key-takeaways\"><strong>Key Takeaways<\/strong><\/h2>\n\n\n\n<p>After completing these first five programs, you should be comfortable with:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Writing a basic C++ program<\/li>\n\n\n\n<li>Displaying output with cout<\/li>\n\n\n\n<li>Reading user input using cin<\/li>\n\n\n\n<li>Performing arithmetic operations<\/li>\n\n\n\n<li>Understanding common data types<\/li>\n\n\n\n<li>Using the sizeof() operator<\/li>\n\n\n\n<li>Recognizing the structure of every C++ program<\/li>\n<\/ul>\n\n\n\n<p>Ready to solve more challenging coding problems? Check out the <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/data-structures-and-algorithms-with-c\"><strong>Data Structures and Algorithms with C++ course by Great Learning Academy Pro<\/strong><\/a> to learn advanced problem-solving techniques and prepare for coding interviews.\u00a0<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/data-structures-and-algorithms-with-c\" class=\"courses-cta-title-link\">C++ Data Structures and Algorithms Course Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master DSA (Data Structures and Algorithms) with C++. Build coding skills in arrays, trees, graphs, heaps, sorting, searching, hashing, and algorithm analysis for interviews.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Intermediate Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>9.17 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/data-structures-and-algorithms-with-c\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-6-swap-two-numbers\"><strong>Program 6: Swap Two Numbers<\/strong><\/h2>\n\n\n\n<p>Swapping two numbers is one of the most common beginner exercises in C++. It introduces variables, assignments, and logical thinking. There are two popular approaches: using a temporary variable and swapping without one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"method-1-swap-using-a-temporary-variable\"><strong>Method 1: Swap Using a Temporary Variable<\/strong><\/h3>\n\n\n\n<p>This is the easiest and most readable approach.<\/p>\n\n\n\n<p id=\"h-c-code-4\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be2986e\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int a = 10, b = 20;\n\n    int temp;\n\n    cout &lt;&lt; &quot;Before Swapping\\n&quot;;\n\n    cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; &quot;, b = &quot; &lt;&lt; b &lt;&lt; endl;\n\n    temp = a;\n\n    a = b;\n\n    b = temp;\n\n    cout &lt;&lt; &quot;\\nAfter Swapping\\n&quot;;\n\n    cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; &quot;, b = &quot; &lt;&lt; b;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-3\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be29875\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Before Swapping\n\na = 10, b = 20\n\nAfter Swapping\n\na = 20, b = 10<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-how-it-works-2\"><strong>How It Works<\/strong><\/p>\n\n\n\n<p>The temporary variable stores the value of a before it's overwritten. Once a receives the value of b, the original value is restored from temp.<\/p>\n\n\n\n<p id=\"h-time-complexity-2\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-2\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"method-2-swap-without-a-temporary-variable\"><strong>Method 2: Swap Without a Temporary Variable<\/strong><\/h3>\n\n\n\n<p>Instead of using an extra variable, arithmetic operations can perform the swap.<\/p>\n\n\n\n<p id=\"h-c-code-5\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be29888\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int a = 10, b = 20;\n\n    a = a + b;\n\n    b = a - b;\n\n    a = a - b;\n\n    cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl;\n\n    cout &lt;&lt; &quot;b = &quot; &lt;&lt; b;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-why-learn-both-methods\"><strong>Why Learn Both Methods?<\/strong><\/p>\n\n\n\n<p>While the arithmetic method is an interesting interview question, the temporary-variable approach is generally preferred because it is easier to read and avoids integer overflow.<\/p>\n\n\n\n<p id=\"h-key-concepts-0\"><strong>Key Concepts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables<\/li>\n\n\n\n<li>Assignment operator<\/li>\n\n\n\n<li>Memory usage<\/li>\n\n\n\n<li>Problem-solving<\/li>\n<\/ul>\n\n\n\n<p id=\"h-common-mistakes-2\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting the correct order of assignments<\/li>\n\n\n\n<li>Using arithmetic swapping with very large integers, which may overflow<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-7-check-whether-a-number-is-even-or-odd\"><strong>Program 7: Check Whether a Number Is Even or Odd<\/strong><\/h2>\n\n\n\n<p>One of the simplest uses of conditional statements is determining whether a number is even or odd.<\/p>\n\n\n\n<p>A number is <strong>even<\/strong> if it is divisible by 2; otherwise, it is <strong>odd<\/strong>.<\/p>\n\n\n\n<p id=\"h-c-code-6\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be2989b\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int number;\n\n    cout &lt;&lt; &quot;Enter a number: &quot;;\n\n    cin &gt;&gt; number;\n\n    if (number % 2 == 0)\n\n        cout &lt;&lt; &quot;Even Number&quot;;\n\n    else\n\n        cout &lt;&lt; &quot;Odd Number&quot;;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-4\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298a1\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter a number: 18\n\nEven Number<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-explanation-0\"><strong>Explanation<\/strong><\/p>\n\n\n\n<p>The modulus (%) operator returns the remainder after division.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the remainder is <strong>0<\/strong>, the number is even.<\/li>\n\n\n\n<li>Otherwise, it is odd.<\/li>\n<\/ul>\n\n\n\n<p id=\"h-time-complexity-3\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-3\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-concepts-covered-1\"><strong>Concepts Covered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>if-else statement<\/li>\n\n\n\n<li>Modulus operator<\/li>\n\n\n\n<li>Decision making<\/li>\n<\/ul>\n\n\n\n<p id=\"h-interview-tip\"><strong>Interview Tip<\/strong><\/p>\n\n\n\n<p>Checking whether a number is even or odd is one of the most frequently asked beginner programming questions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-8-check-whether-a-character-is-a-vowel-or-consonant\"><strong>Program 8: Check Whether a Character Is a Vowel or Consonant<\/strong><\/h2>\n\n\n\n<p>This program introduces character variables and logical operators.<\/p>\n\n\n\n<p id=\"h-c-code-7\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298b2\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    char ch;\n\n    cout &lt;&lt; &quot;Enter a character: &quot;;\n\n    cin &gt;&gt; ch;\n\n    if (ch==&#039;a&#039;||ch==&#039;e&#039;||ch==&#039;i&#039;||ch==&#039;o&#039;||ch==&#039;u&#039;||\n\n        ch==&#039;A&#039;||ch==&#039;E&#039;||ch==&#039;I&#039;||ch==&#039;O&#039;||ch==&#039;U&#039;)\n\n        cout &lt;&lt; &quot;Vowel&quot;;\n\n    else\n\n        cout &lt;&lt; &quot;Consonant&quot;;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-5\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298b8\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter a character: E\n\nVowel<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-how-it-works-3\"><strong>How It Works<\/strong><\/p>\n\n\n\n<p>The program compares the entered character with all five vowels in both uppercase and lowercase.<\/p>\n\n\n\n<p>If none match, it assumes the character is a consonant.<\/p>\n\n\n\n<p id=\"h-time-complexity-4\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-4\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-common-mistakes-3\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting uppercase vowels<\/li>\n\n\n\n<li>Entering digits instead of letters<\/li>\n\n\n\n<li>Not validating special characters<\/li>\n<\/ul>\n\n\n\n<p id=\"h-key-concepts-1\"><strong>Key Concepts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Character data type<\/li>\n\n\n\n<li>Logical OR operator<\/li>\n\n\n\n<li>Conditional statements<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-9-check-whether-a-year-is-a-leap-year\"><strong>Program 9: Check Whether a Year Is a Leap Year<\/strong><\/h2>\n\n\n\n<p>Leap year calculations are a classic example of nested conditional logic.<\/p>\n\n\n\n<p>A year is considered a leap year if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is divisible by <strong>400<\/strong>, or<\/li>\n\n\n\n<li>It is divisible by <strong>4<\/strong> but not divisible by <strong>100<\/strong><\/li>\n<\/ul>\n\n\n\n<p id=\"h-c-code-8\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298ca\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int year;\n\n    cout &lt;&lt; &quot;Enter year: &quot;;\n\n    cin &gt;&gt; year;\n\n    if ((year % 400 == 0) ||\n\n       (year % 4 == 0 &amp;&amp; year % 100 != 0))\n\n        cout &lt;&lt; &quot;Leap Year&quot;;\n\n    else\n\n        cout &lt;&lt; &quot;Not a Leap Year&quot;;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-sample-output-0\"><strong>Sample Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298d1\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter year: 2028\n\nLeap Year<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-why-this-program-is-important\"><strong>Why This Program Is Important<\/strong><\/p>\n\n\n\n<p>This example introduces multiple logical conditions, making it an excellent exercise for understanding real-world decision-making.<\/p>\n\n\n\n<p id=\"h-complexity-1\"><strong>Complexity<\/strong><\/p>\n\n\n\n<p>Time: <strong>O(1)<\/strong><\/p>\n\n\n\n<p>Space: <strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-concepts-covered-2\"><strong>Concepts Covered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Logical AND (&amp;&amp;)<\/li>\n\n\n\n<li>Logical OR (||)<\/li>\n\n\n\n<li>Nested conditions<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-10-find-the-largest-of-three-numbers\"><strong>Program 10: Find the Largest of Three Numbers<\/strong><\/h2>\n\n\n\n<p>Finding the maximum value among multiple inputs is another popular beginner program.<\/p>\n\n\n\n<p id=\"h-c-code-9\"><strong>C++ Code<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298eb\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">c++<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nint main() {\n\n    int a, b, c;\n\n    cout &lt;&lt; &quot;Enter three numbers: &quot;;\n\n    cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;\n\n    if (a &gt;= b &amp;&amp; a &gt;= c)\n\n        cout &lt;&lt; &quot;Largest = &quot; &lt;&lt; a;\n\n    else if (b &gt;= a &amp;&amp; b &gt;= c)\n\n        cout &lt;&lt; &quot;Largest = &quot; &lt;&lt; b;\n\n    else\n\n        cout &lt;&lt; &quot;Largest = &quot; &lt;&lt; c;\n\n    return 0;\n\n}<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-output-6\"><strong>Output<\/strong><\/p>\n\n\n\n<div id=\"copy-6a70e5be298f0\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Enter three numbers:\n\n25 12 18\n\nLargest = 25<\/code><\/pre><\/div>\n\n\n\n<p id=\"h-explanation-1\"><strong>Explanation<\/strong><\/p>\n\n\n\n<p>The program compares the first number against the other two.<\/p>\n\n\n\n<p>If it isn't the largest, it checks the second number.<\/p>\n\n\n\n<p>If neither condition is true, the third number must be the largest.<\/p>\n\n\n\n<p id=\"h-time-complexity-5\"><strong>Time Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-space-complexity-5\"><strong>Space Complexity<\/strong><\/p>\n\n\n\n<p><strong>O(1)<\/strong><\/p>\n\n\n\n<p id=\"h-concepts-covered-3\"><strong>Concepts Covered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Nested conditions<\/li>\n\n\n\n<li>Comparison operators<\/li>\n\n\n\n<li>Logical operators<\/li>\n<\/ul>\n\n\n\n<p id=\"h-common-mistakes-4\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using > instead of >=<\/li>\n\n\n\n<li>Forgetting the else if<\/li>\n\n\n\n<li>Missing braces in complex conditions<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"final-thoughts\"><strong>Final Thoughts<\/strong><\/h2>\n\n\n\n<p>Writing simple C++ programs is one of the fastest ways to build a strong programming foundation. Each exercise teaches a specific concept\u2014whether it's taking user input, making decisions with conditional statements, working with loops, or solving basic mathematical problems.<\/p>\n\n\n\n<p>The key is consistency. Rather than trying to learn everything at once, practice a few programs each day, experiment with the code, and gradually increase the complexity of your projects. As your confidence grows, you'll be ready to tackle more advanced C++ topics such as object-oriented programming, templates, and the Standard Template Library.<\/p>\n\n\n\n<p>By mastering these 10 beginner-friendly programs, you'll develop the problem-solving skills and coding habits needed for academic success, technical interviews, and software development projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\"><strong>Frequently Asked Questions<\/strong><\/h2>\n\n\n\n<p><strong>Question: What is the easiest C++ program for beginners?<\/strong><\/p>\n\n\n\n<p>The easiest C++ program for beginners is the <strong>Hello World<\/strong> program. It introduces the basic structure of a C++ application, including the main() function, the &lt;iostream&gt; header, and the cout statement for output.<\/p>\n\n\n\n<p><strong>Question: How many C++ programs should beginners practice?<\/strong><\/p>\n\n\n\n<p>Beginners should practice at least <strong>30 to 50 C++ programs<\/strong> covering topics like variables, operators, loops, functions, arrays, strings, and object-oriented programming. Regular practice improves coding skills and problem-solving ability.<\/p>\n\n\n\n<p><strong>Question: Is C++ difficult to learn?<\/strong><\/p>\n\n\n\n<p>C++ has a steeper learning curve than some modern programming languages because it introduces concepts like memory management, pointers, and object-oriented programming. However, learning one concept at a time and practicing consistently makes it much easier to master.<\/p>\n\n\n\n<p><strong>Question: Which IDE is best for C++ programming?<\/strong><\/p>\n\n\n\n<p>Some of the most popular C++ IDEs include Visual Studio Code, Code::Blocks, CLion, Visual Studio, and Dev-C++. Choose an IDE that provides syntax highlighting, debugging tools, and compiler support to make development easier.<\/p>\n\n\n\n<p><strong>Question: What should I learn after these beginner C++ programs?<\/strong><\/p>\n\n\n\n<p>After completing these programs, you should move on to arrays, strings, functions, recursion, pointers, structures, classes and objects, the Standard Template Library (STL), and data structures and algorithms. These topics build the skills required for interviews and real-world software development.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn C++ with 10 simple programs for beginners, complete with source code, outputs, explanations, and key programming concepts.<\/p>\n","protected":false},"author":41,"featured_media":119106,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[],"content_type":[],"class_list":["post-48292","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Simple C++ Programs<\/title>\n<meta name=\"description\" content=\"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple C++ Programs\" \/>\n<meta property=\"og:description\" content=\"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-28T07:14:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-30T10:19:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1734\" \/>\n\t<meta property=\"og:image:height\" content=\"907\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Simple C++ Programs\",\"datePublished\":\"2021-10-28T07:14:21+00:00\",\"dateModified\":\"2026-07-30T10:19:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/\"},\"wordCount\":2333,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/image-7.png\",\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/\",\"name\":\"Simple C++ Programs\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/image-7.png\",\"datePublished\":\"2021-10-28T07:14:21+00:00\",\"dateModified\":\"2026-07-30T10:19:20+00:00\",\"description\":\"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/image-7.png\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/image-7.png\",\"width\":1734,\"height\":907,\"caption\":\"Learn C++ by practicing 10 beginner-friendly programs with complete source code, sample outputs, and step-by-step explanations.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/simple-c-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Simple C++ Programs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Simple C++ Programs","description":"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/","og_locale":"en_US","og_type":"article","og_title":"Simple C++ Programs","og_description":"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-10-28T07:14:21+00:00","article_modified_time":"2026-07-30T10:19:20+00:00","og_image":[{"width":1734,"height":907,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png","type":"image\/png"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Simple C++ Programs","datePublished":"2021-10-28T07:14:21+00:00","dateModified":"2026-07-30T10:19:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/"},"wordCount":2333,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png","articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/","url":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/","name":"Simple C++ Programs","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png","datePublished":"2021-10-28T07:14:21+00:00","dateModified":"2026-07-30T10:19:20+00:00","description":"C++ Programs: C++ is a very simple language, Following are some C++ programs that you can practice to have a strong grasp of the language.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png","width":1734,"height":907,"caption":"Learn C++ by practicing 10 beginner-friendly programs with complete source code, sample outputs, and step-by-step explanations."},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/simple-c-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Simple C++ Programs"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png",1734,907,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-150x150.png",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-300x157.png",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-768x402.png",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-1024x536.png",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-1536x803.png",1536,803,true],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7.png",1734,907,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-640x853.png",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-96x96.png",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/10\/image-7-150x78.png",150,78,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn C++ with 10 simple programs for beginners, complete with source code, outputs, explanations, and key programming concepts.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/48292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=48292"}],"version-history":[{"count":11,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/48292\/revisions"}],"predecessor-version":[{"id":119111,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/48292\/revisions\/119111"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/119106"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=48292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=48292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=48292"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=48292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}