C++
Перейти к навигации
Перейти к поиску
Hello World
Объявление переменных
1 int i, j, k = 10;
2 char c, ch = 'a';
3 float f, salary = 4.5f;
4 double d = 100.3;
5 bool busy = true;
Ввод и вывод
1 int age;
2 std::cout << "Please enter your age:";
3 std::cin >> age;
4 std::cout << "Your age = " << age << std::endl;
Условный оператор
1 int age;
2 std::cout << "Please enter your age:";
3 std::cin >> age;
4 if (age > 65)
5 {
6 std::cout << "Here is your pension.";
7 }
8 else
9 {
10 std::cout << "Good morning people!";
11 }
Циклы
1 std::cout << "while loop" << std::endl;
2 int i = 1;
3 while (i < 11)
4 {
5 std::cout << i << std::endl;
6 i++;
7 }
8
9 std::cout << "do while loop" << std::endl;
10 i = 1;
11 do
12 {
13 std::cout << i << std::endl;
14 i++;
15 } while (i < 11);
16
17 printf("for loop\n");
18 for (int j = 1; j < 11; j++)
19 {
20 std::cout << j << std::endl;
21 }