Computer code

HTML has elements for formatting computer code:

  • <code> - programming code
  • <kbd> - keyboard input
  • <samp> - computer output
  • <var> - variable
  • <pre> - preformatted text, it's keep all spaces and newlines

Visual appearance of the element can be changed by css. In our example bootstrap library used.
For pretty code you can use js library like highlightjs.

code
<pre class="c++"><code>#include &lt;iostream&gt;
using namespace std;
int main()
{
    int n;
    cout &lt;&lt; &quot;Enter a positive integer: &quot;;
    cin &gt;&gt; n;
    for (int i = 1; i &lt;= 10; ++i) {
        cout &lt;&lt; n 
               &lt;&lt; &quot; * &quot; 
               &lt;&lt; i 
               &lt;&lt; &quot; = &quot; 
               &lt;&lt; n * i 
               &lt;&lt; endl;
    }
    
    return 0;
}
</code></pre>
<hr>
<p>Press<kbd>Ctrl + S</kbd> for save.</p>
result
#include <iostream>
using namespace std;
int main()
{
    int n;
    cout << "Enter a positive integer: ";
    cin >> n;
    for (int i = 1; i <= 10; ++i) {
        cout << n 
              << " * " 
              << i 
              << " = " 
              << n * i 
              << endl;
    }
    
    return 0;
}

Press Ctrl + S for save.