AlgoViz

Cpp Basics

Easy

Headers, main(), input and output

Problem

Get comfortable with the building blocks of a C++ program: including headers, the main() entry point, reading input with cin, printing with cout, and basic data types (int, long long, double, char, bool, string).

In simple words

The starter kit of a program: read input, do something, print output.

The idea

Every C++ program starts at main(). You include the headers you need, read input from cin, compute, and write to cout. Competitive and interview code keeps this skeleton tiny so the interesting part is the algorithm, not the plumbing.

The trick

  • `#include <bits/stdc++.h>` pulls in the whole standard library in one line — convenient for practice, not for production.
  • `cin >> x` stops at whitespace; use `getline(cin, s)` when the input is a whole line including spaces.
  • `\n` is cheaper than `endl`, which also flushes the stream on every call.

This one walks through the worked example rather than tracing the algorithm frame by frame — a full walkthrough is still to be drawn. The code and the idea below are the real solution.

5
0

Step 1 of 2. Here's the example — 5 Values: 5.

1/2
Optimal
timespace
1#include <bits/stdc++.h>2using namespace std;3int main() {4  int n; cin >> n;          // read input5  cout << "Hello " << n;    // print output6  return 0;7}

Input

array
[5]

Output

answer

Check yourself

1 quick question about this walkthrough. A wrong answer costs nothing.

Example

Input:
5
Output:
Hello 5
Explanation:
cin >> n reads the number into n, and cout writes it back out. Every problem you solve is this shape with more in the middle.

Finished the walkthrough? Add it to your streak.