ProgramsC++

Basic Programs

Basic C++ programs for cout, cin, types, and simple math. First week, walked line by line.

14 programs · open one, then the next

Start with Hello World
  1. 01Hello WorldBeginnerPrints "Hello World" in C++ with cout. Covers #include, main, and return 0.Open example →
  2. 02Display Your NameBeginnerStore a name in a C++ string and print it with cout.Open example →
  3. 03User InputBeginnerRead a name and age in C++ with cin. cin >> stops at the first space.Open example →
  4. 04Sum of Two NumbersBeginnerAdd two integers in C++ and print the sum. Watch int overflow and failed cin.Open example →
  5. 05Swap Two NumbersBeginnerSwap two numbers in C++ using a temporary variable.Open example →
  6. 06Size of int, float, double, charBeginnerPrint sizeof char, int, float, double, and long in C++. long is 4 or 8 bytes depending on the OS.Open example →
  7. 07Float MultiplicationBeginnerMultiply two floats in C++ and print two decimal places with setprecision. Needs iomanip.Open example →
  8. 08ASCII Value of a CharacterBeginnerPrint the ASCII value of a character in C++ by casting char to int. 'A' is 65.Open example →
  9. 09Convert Fahrenheit to CelsiusBeginnerConvert Fahrenheit to Celsius in C++. 5/9 as integers is 0 — use 5.0/9.0.Open example →
  10. 10Calculate Simple InterestBeginnerSimple interest in C++: P × R × T / 100. Rate 5 means 5%, not 0.05.Open example →
  11. 11Calculate Compound InterestBeginnerCompound interest in C++ with pow. ^ is XOR, not exponent.Open example →
  12. 12Area and Perimeter of RectangleBeginnerArea and perimeter of a rectangle in C++ from length and width.Open example →
  13. 13Find Quotient and RemainderBeginnerQuotient and remainder in C++ using / and %. 7/2 is 3.Open example →
  14. 14Add Two NumbersBeginnerAdd two numbers in C++ with cin and cout.Open example →