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 <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;
}
</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.