Рубрика: C++

  • Урок 11, с++, работа с массивами, добавление элементов и вставка элементов в массив.

    Урок 11, с++, работа с массивами, добавление элементов и вставка элементов в массив.

    Видео к уроку.

    Код к уроку.

    // ConsoleApplication3.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    void add(int value, int *product,int &count)
    {
      product[count] = value;
      count++;
    
    }
    void insert(int value, int pos,int *product, int &count)
    {
      for (int i = count - 1; i >=pos; i--)
        product[i + 1] = product[i];
      product[pos] = value;
      count++;
    }
    void print(int *product, int &count)
    {
      for (int i = 0; i < count; i++)
        cout << product[i]<<"\n";
      cout << "------------------------------";
    }
    int main()
    {
      int product[100];
      int count = 0;
      add(1, product, count);
      add(3, product, count);
      add(5, product, count);
      insert(2,1, product, count);
      insert(4, 3, product, count);
      print( product, count);
      int a;
      cin >> a;
      return 0;
    }
    
    

     

  • Урок 10. с++. Стеки в с++. Программирование стеков.

    Урок 10. с++. Стеки в с++. Программирование стеков.

    Видео к уроку.

    Код к уроку.

    Стек  FIFO

    // ConsoleApplication3.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    //пример реализации стека FIFO
    
    int pop(int *product, int &pos)//извлекать товары
    {
      if (pos == 0)
      {
        cout << "stack empty";
        return -1;
      }
      pos--;
      int ret=product[0];
      for (int i = 1; i <= pos; i++)
      {
        product[i - 1] = product[i];
      }
      return ret;
    }
    void push(int item, int *product, int &pos)//помещаем в массив
    {
      if (pos == 99)
      {
        cout << "stack overflow";
        return;
      }
      product[pos] = item;
      pos++;
    }
    int main()
    {
      int pos = 0;
      int product[100];
      push(10, product, pos);
      push(11, product, pos);
      push(12, product, pos);
      cout << pop(product, pos) << "\n";
      cout << pop(product, pos) << "\n";
      cout << pop(product, pos) << "\n";
      int a;
      cin >> a;
      return 0;
    }
    
    

    Стек LIFO

    // ConsoleApplication3.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    //пример реализации стека LIFO
    
    int pop(int *product, int &pos)//извлекать товары
    {
      if (pos ==0)
      {
        cout << "stack empty";
        return -1;
      }
      pos--;
      product[pos];
      
      return product[pos];
    }
    void push(int item, int *product, int &pos)//помещаем в массив
    {
      if (pos == 99)
      {
        cout << "stack overflow";
        return;
      }
      product[pos] = item;
      pos++;
    }
    int main()
    {
      int pos = 0;
      int product[100];
      push(10, product, pos);
      push(11, product, pos);
      push(12, product, pos);
      cout << pop(product, pos)<<"\n";
      cout << pop(product, pos) << "\n";
      cout << pop(product, pos) << "\n";
      int a;
      cin >> a;
      return 0;
    }
    
    

     

  • Урок 9. Работа с файлами в с++

    Урок 9. Работа с файлами в с++

    Видео для урока.

    Код урока.

    // ConsoleApplication3.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
      ofstream myfile;
      myfile.open("login.txt");
      myfile << "admin";
      myfile.close();
      myfile.open("password.txt");
      myfile << "123";
      myfile.close();
      ifstream file("password.txt");
      char *pass1;
      pass1 = new char[100];
      char *login1;
      login1 = new char[100];
      
      file.getline(pass1,'\n');
      file.close();
      file.open("login.txt");
      file.getline(login1, '\n');
      
      char *login;
      char *password;
      login = new char[100];
      password = new char[100];
      cout << "Enter login: ";
      cin >> login;
      cout << "Enter password: ";
      cin >> password;
      if (strcmp(login, login1) == 0 && strcmp(pass1, password) == 0)
      {
        cout << "Hello admin.";
      }
      else
        {
        cout << "You are wrong.";
        }
      cin >> password;
      delete [] pass1;
      delete [] login;
      delete [] password;
      return 0;
    }
    
    

     

  • Урок 4. Функции в C++

    Задания на функции.

    1. Написать функцию которая возвращает true если число четное и false если число нечетное.
    2. Написать функцию которая переводит градусы Цельсия в градусы Фаренгейта.
    3. Написать функцию которая возвращает сумму целых чисел в указанном диапазоне.
    4. Написать функцию которая возводит число в указанную степень. В функцию передаются два параметра число и степень в которую его нужно возвести.
    5. Написать функцию которая разворачивает число. К примеру если в функцию передать 123 то она вернет 321.
    6. Написать функцию которая будет высчитывать одну 12 от переданного числа.
    7. Написать функцию которая будет переводить в шестнадцатеричный формат входящее десятичное число от 0 до 15.
    8. Написать функцию которая будет возвращать столицу по переданному как параметр городу.
    9. Написать функцию которая из трех переданных переменных вернет максимальную.
    10. Написать функцию которая из 4х переданных переменных в виде параметров функции вернет среднее значение.
  • Урок 3. C++. Массивы и структуры

    Урок 3. C++. Массивы и структуры

    Код урока.

    // ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
    //
    
    #include "pch.h"
    #include <iostream>
    #include <Windows.h>
    #include <string>
    using namespace std;
    
    struct student
    {
      int age;
      string name;
      
    };
    struct group
    {
      student s[10];
      string name;
    };
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
      int age[30];
      string name[3];
      name[0] = "Василий";
      name[1] = "Михаил";
      name[2] = "Павел";
      for (int i = 0; i < 30; i++)
      {
        age[i] = rand()%100;
      }
      for (int i = 0; i < 30; i++)
      {
        cout << age[i] << " ";
      }
      cout << "\n";
      for (int i = 0; i < 3; i++)
      {
        cout << name[i] << " ";
      }
      //----------------Поиск максимального значения.
      int max = age[0];
      for (int i = 1; i < 30; i++)
      {
        if(max < age[i])
          max=age[i];
      }
      cout <<"\nМаксимальное значение = "<< max << " ";
      //----------------смена двух переменных местами-----------------------
      int a, b;
      a = 10;
      b = 12;
      int temp=a;
      a = b;
      b = temp;
      cout << "\na=" << a<< " ";
      cout << "\nb=" << b << " ";
      //----------------сортировка массива-----------------------
      for (int i = 0; i < 30; i++)
      {
        int max, pos;
        pos = i;
        max = age[i];
        for (int j = i; j < 30; j++)
          {
          if (max < age[j])
            {
            max = age[j];
            pos = j;
            }
          }
        int temp = age[i];
        age[i] = age[pos];
        age[pos] = temp;
    
      }
      //---------------------Вывод массива
      cout << "\n";
      for (int i = 0; i < 30; i++)
      {
        cout << age[i] << " ";
      }
      
      student vasya;
      vasya.age = 20;
      
      vasya.name = "Василий";
      student stud[10];
      stud[0].age = 10;
      stud[0].name = "Николай";
      
      group g[10];
      g[0].name = "ЭА 2015";
      g[0].s[0].age = 20;
      g[0].s[0].name= "Василий";
    
    }
    

     

  • Урок 2. C++. Операторы ветвления кода и циклы.

    Урок 2. C++. Операторы ветвления кода и циклы.

    Код к уроку:

    // ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
    //
    
    #include "pch.h"
    #include <iostream>
    #include <Windows.h>
    #include <string>
    using namespace std;
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
      int a, b;
      a = 1;
      b = 1;
    
      if (a == b) {
        std::cout << "Переменная а=b!\n";
      }
      if (a != b) {
        std::cout << "Переменная а не равна b!\n";
      }
      if (a > b) {
        std::cout << "Переменная а больше b!\n";
      }
      if (a < b) {
        std::cout << "Переменная а меньше b!\n";
      }
      if (a >= b) {
        std::cout << "Переменная а больше или равна b!\n";
      }
      if (a <= b) {
        std::cout << "Переменная а меньше или равна b!\n";
      }
      //полная форма оператора if
      if (a==b){
        std::cout << "Переменная а=b!\n";
      }
      else {
        std::cout << "Переменная а не равна b!\n";
      }
    
      string  login, password;
      string  login1, password1;
      login = "admin";
      password = "123";
      login1 = "admin1";
      password1 = "1234";
    
      if (login == "admin" && password == "123")
      {
        std::cout << "Логин и пароль введены верно. !\n";
      }
      if ((login == "admin" && password == "123") || (login1 == "admin1" && password1 == "1234"))
      {
        std::cout << "Логин и пароль введены верно. !\n";
      }
    
      if(login == "admin" && password == "123")
        std::cout << "Логин и пароль введены верно. !\n";
      else 
        std::cout << "Логин и пароль введены неверно. !\n";
      if (login == "admin")
      {
        std::cout << "Логин введен неверно. !\n";
        if (password == "123")
        {
          std::cout << "Пароль введен неверно. !\n";
        }
      }
    
      int answer = 1;
      if (answer == 1)
      {
        //выполняем код для ответа 1
      }
      else
      {
        if (answer == 2)
        {
          // код для ответа 2
        }
        else
        {
          if (answer == 3)
          {
          //код для ответа 3
          }
        }
      }
      answer =2;
      switch (answer)
      {
      case 1:
        std::cout << "Верно. !\n";
        break;
      case 2:
        std::cout << "Неверно. !\n";
        break;
      case 3:
        std::cout << "Неверно. !\n";
        break;
      default:
        std::cout << "Вы ввели  неверное значение. !\n";
        
    
      }
      cout << "a= " << a;
    
      for (int i = 0; i < 10; i++)
      {
        cout << "\n i= " << i;
    
      }
      cout << "\n Конец цикла";
      for (int i = 0; i < 10; i+=2)
      {
        cout << "\n i= " << i;
    
      }
      cout << "\n Конец цикла";
      for (int i = 9; i >=0; i--)
      {
        cout << "\n i= " << i;
    
      }
      cout << "\n Конец цикла\n";
      for (int i = 1; i < 10; i++)
      {
        for (int j =1; j < 10; j++)
        {
          cout <<i <<"*"<<j<<"="<<i*j<<"\t";
        }
        cout << "\n";
    
      }
      cout << "\n Конец цикла";
      int i = 10;
      while (i > 0)
      {
        i--;
        cout << "\n i= " << i;
    
      }
      i =10;
      do {
        i--;
        cout << "\n i= " << i;
    
      } while (i > 0);
    
    
    }
    
    // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
    // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
    
    // Советы по началу работы 
    //   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
    //   2. В окне Team Explorer можно подключиться к системе управления версиями.
    //   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
    //   4. В окне "Список ошибок" можно просматривать ошибки.
    //   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
    //   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
    

     

  • Урок 1. С++ Первый урок.

    Урок 1. С++ Первый урок.

    План урока:

    1.  Переменные.
    2. Системы исчисления.
    3. Арифметические операторы.
    4. Битовые операторы
    5. Переполнение переменных.
    6. Вывод в консоль.
    7. Чтение из консоли.
    8. Операторы ветвления кода. Понятие алгоритм.
    9. Алгоритм смены двух переменных местами.
    10. Оператор if else
    11. Оператор switch case
    12. Кодировка CP1251

    Задания.

    1. Прочитать с консоли свое имя и вывести строку приветствия.  Приветствуем вас ИМЯ в нашей первой программе. Вместо слова имя нужно подставить значение считанное с консоли.
    2. Вывести в консоль значения от 1 до 10 используя инкремент.
    3. Вывести в консоль значения от 10 до 1 используя декремент.
    4. Показать результат переполнения переменной на примере своего кода.
    5. В бинарном виде выставить третий бит в 1.
    6. Проверить наличие 1 в третьем бите и вывести результат в консоль.
    7. Составьте алгоритм для задания 8.
    8. Используя алгоритмы смены двух переменных местами и алгоритм  поиска максимального числа поменяйте две переменные местами если a>b. Иными словами нужно написать код для того чтобы переменная а всегда была меньше b не зависимо от исходных значений.

     

  • Примеры решения заданий по c++ в visual studio

    Решение к задаче 1.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "1. Выводим в строку значения от 0 до 10 \n";
    
      for (int i = 0; i <= 10; i++)
      {
        cout << i;
        cout << ";";
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 2.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n2. Выводим в строку значения от 10 до 0 \n";
    
      for (int i = 10; i >= 0; i--)
      {
        cout << i;
        cout << ";";
    
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 3.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n3. Выводим в строку значения от 60 до 100 \n";
    
      for (int i = 60; i <= 100; i++)
      {
        cout << i;
        cout << ";";
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 4.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n4. Выводим в строку значения от -39 до 100 \n";
    
      for (int i = -39; i <= 100; i++)
      {
        cout << i;
        cout << ";";
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 5.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n5. Выводим в строку четные числа от 2 до 50\n";
    
      for (int i = 2; i <= 50; i += 2)
      {
        cout << i;
        cout << ";";
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 6.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n6. Выводим в строку нечетные числа от 1 до 49\n";
    
      for (int i = 1; i <= 49; i += 2)
      {
        cout << i;
        cout << ";";
      }
      system("pause");
      return 0;
    }
    

    Задачи на вложенные циклы и на матрицы с использованием операторов for и if на c++.

    Решение к задаче 7.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n7. Выводим таблицу  нулей 10x10\n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1; x <= 10; x++)
        {
    
          cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    }
    

    Решение к задаче 8.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n8. Выводим таблицу  нулей с диагональю из единиц 10x10\n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x==y)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 9.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n9. Выводим таблицу  с рамочкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x==1 || x==10 ||y==1 || y==10 )
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решения к задаче 10.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n10. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(y<=5)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 11.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n11. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(y<=5)
            cout << 0;
          else
            cout << 1;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 12.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n12. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x<=5)
            cout << 0;
          else
            cout << 1;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 13.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n13. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x<=5)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 14.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n14. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x>y)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 15.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n15. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x>=10-y+1)
            cout << 0;
          else
            cout << 1;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 16.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n16. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if(x>=10-y+1)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 17.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n17. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ( (x >= 10 - y + 1 && x<=y) || (x <= 10 - y + 1 && x>=y))
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 18.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n18. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ( y >= 10 - x + 1 && y<=x)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 19.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n19. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ( x >= 10 - y + 1 && x<=y)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 20.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n20. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ( y <= 10 - x + 1 && y>=x)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 21.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n21. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if (x <= 10 - y + 1 && x>=y)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 22.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n22. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ((x <10 - y + 1 && x>y) || (x > 10 - y + 1 && x < y))
            cout << 0;
          else
            cout << 1;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

    Решение к задаче 23.

    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      SetConsoleCP(1251);
      SetConsoleOutputCP(1251);
    
    
    
      cout << "\n23. Выводим таблицу  с заливкой \n";
    
      for (int y = 1; y <= 10; y++)
      {
        for (int x = 1;x <= 10;x++)
        {
    
          if ( (x ==3 && y>2 && y<9)  || (x == 8 && y>2 && y<9) || (y == 3 && x>2 && x<9) || (y == 8 && x>2 && x<9) || x==1 || y==1 || x==10 || y==10)
            cout << 1;
          else
            cout << 0;
          cout << " ";
        }
        cout << "\n";
      }
      system("pause");
      return 0;
    
    }
    

     

     

  • Задания по программированию на C++

    Задание:

    1. Вывести в строку значения от 0 до 10 включительно
    2. Вывести в строку значения от 10 до 0 включительно
    3. Вывести в строку значения от 60 до 100
    4. Вывести в столбец значения от -39 до 100
    5. Вывести в строку четные числа от 0 до 10
    6. Вывести в строку нечетные числа от 1 до 9.
    7. Вывести в строку ряд 100 200 300 …..1000
    8. Вывести рисунки как на картинке ниже используя циклы

     

    9. Вывести таблицу из нулей

    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    

    10. Вывести таблицу c диагональю из 1
    
    1 0 0 0 0 0 0 0 0
    0 1 0 0 0 0 0 0 0
    0 0 1 0 0 0 0 0 0
    0 0 0 1 0 0 0 0 0
    0 0 0 0 1 0 0 0 0
    0 0 0 0 0 1 0 0 0
    0 0 0 0 0 0 1 0 0
    0 0 0 0 0 0 0 1 0
    0 0 0 0 0 0 0 0 1
    

    11. Вывести таблицу c рамочкой из 1
    
    1 1 1 1 1 1 1 1 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 0 0 0 0 0 0 0 1
    1 1 1 1 1 1 1 1 1
    

    12. Вывести таблицу c заливкой верхней части 
    
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    

    13. Вывести таблицу c заливкой нижней части
    
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1
    

    14. Вывести таблицу c заливкой по образцу
    
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 1 1 1 1
    

    15. Вывести таблицу c заливкой по образцу
    
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    

    15. Вывести таблицу c заливкой по образцу
    0 1 1 1 1 1 1 1 1
    0 0 1 1 1 1 1 1 1
    0 0 0 1 1 1 1 1 1
    0 0 0 0 1 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 0 1 1 1
    0 0 0 0 0 0 0 1 1
    0 0 0 0 0 0 0 0 1
    0 0 0 0 0 0 0 0 0
    

    16. Вывести таблицу c заливкой по образцу
    
    1 1 1 1 1 1 1 1 0
    1 1 1 1 1 1 1 0 0
    1 1 1 1 1 1 0 0 0
    1 1 1 1 1 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 0 0 0 0 0 0
    1 1 0 0 0 0 0 0 0
    1 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    

    17. Вывести таблицу c заливкой по образцу
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 1
    0 0 0 0 0 0 0 1 1
    0 0 0 0 0 0 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 1 1 1 1 1
    0 0 0 1 1 1 1 1 1
    0 0 1 1 1 1 1 1 1
    0 1 1 1 1 1 1 1 1
    

    18. Вывести таблицу c заливкой по образцу
    1 1 1 1 1 1 1 1 1
    0 1 1 1 1 1 1 1 0
    0 0 1 1 1 1 1 0 0
    0 0 0 1 1 1 0 0 0
    0 0 0 0 1 0 0 0 0
    0 0 0 1 1 1 0 0 0
    0 0 1 1 1 1 1 0 0
    0 1 1 1 1 1 1 1 0
    1 1 1 1 1 1 1 1 1
    

    19. Вывести таблицу c заливкой по образцу
    0 0 0 0 0 0 0 0 1
    0 0 0 0 0 0 0 1 1
    0 0 0 0 0 0 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 1 1 1 1 1
    0 0 0 0 0 1 1 1 1
    0 0 0 0 0 0 1 1 1
    0 0 0 0 0 0 0 1 1
    0 0 0 0 0 0 0 0 1
    

    20. Вывести таблицу c заливкой по образцу
    
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 1 0 0 0 0
    0 0 0 1 1 1 0 0 0
    0 0 1 1 1 1 1 0 0
    0 1 1 1 1 1 1 1 0
    

    21. Вывести таблицу c заливкой по образцу
    1 0 0 0 0 0 0 0 0
    1 1 0 0 0 0 0 0 0
    1 1 1 0 0 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 1 1 0 0 0 0
    1 1 1 1 0 0 0 0 0
    1 1 1 0 0 0 0 0 0
    1 1 0 0 0 0 0 0 0
    1 0 0 0 0 0 0 0 0
    

    22. Вывести таблицу c заливкой по образцу
    0 1 1 1 1 1 1 1 0
    0 0 1 1 1 1 1 0 0
    0 0 0 1 1 1 0 0 0
    0 0 0 0 1 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    

    23. Вывести таблицу c заливкой по образцу
    1 0 0 0 0 0 0 0 1
    1 1 0 0 0 0 0 1 1
    1 1 1 0 0 0 1 1 1
    1 1 1 1 0 1 1 1 1
    1 1 1 1 1 1 1 1 1
    1 1 1 1 0 1 1 1 1
    1 1 1 0 0 0 1 1 1
    1 1 0 0 0 0 0 1 1
    1 0 0 0 0 0 0 0 1
    

    24. Вывести таблицу c заливкой по образцу
    1 1 1 1 1 1 1 1 1
    1 0 0 0 0 0 0 0 1
    1 0 1 1 1 1 1 0 1
    1 0 1 0 0 0 1 0 1
    1 0 1 0 1 0 1 0 1
    1 0 1 0 0 0 1 0 1
    1 0 1 1 1 1 1 0 1
    1 0 0 0 0 0 0 0 1
    1 1 1 1 1 1 1 1 1
    

    25. Вывести таблицу c заливкой по образцу
    1 1 1 1 1 1 1 1 1
    1 0 0 0 0 0 0 0 1
    1 1 1 1 1 1 1 0 1
    1 0 0 0 0 0 1 0 1
    1 0 1 1 1 0 1 0 1
    1 0 1 0 0 0 1 0 1
    1 0 1 1 1 1 1 0 1
    1 0 0 0 0 0 0 0 1
    1 1 1 1 1 1 1 1 1
    

Яндекс.Метрика