Блог

  • Урок 1. PHP. Форма входа. Создание своего движка на PHP.

    Урок 1. PHP. Форма входа. Создание своего движка на PHP.

    Архив файлов урока можно скачать по ссылке ниже.

    engine.com
    Видео с урока.

  • Код для пагинации PHP

    <?
    //1. Задаем переменные
    $items=430;
    $items_per_page=25;
    $pages_in_paginator=11;
    $paginator_offset=floor($pages_in_paginator/2);
    //2. Рассчитываем количество страниц.
    $page_count=ceil($items/$items_per_page);
    //3. Если не задана страница в гет параметре то мы ее приравниваем к нулю.
    if(!isset($_GET['page']))
      $_GET['page']=0;
    $cur_page=intval($_GET['page']);
    if($cur_page>=$page_count)$cur_page=$page_count-1;
    
    //4. Рассчет первой страницы для вывода в пагинаторе
    $start_page_pagination=$cur_page-$paginator_offset;
    if($start_page_pagination<0)$start_page_pagination=0;
    //5. Рассчет последней страницы для вывода в пагинаторе
    $end_page_pagination=$start_page_pagination+$pages_in_paginator;
    if($end_page_pagination>=$page_count)$end_page_pagination=$page_count-1;
    
    if($end_page_pagination-$start_page_pagination<$pages_in_paginator && $page_count>$pages_in_paginator)
    {
      $end_page_pagination=$page_count-1;
      $start_page_pagination=$end_page_pagination-$pages_in_paginator;
    }
    ?>
    <a href='?page=0'><<</a> | 
    <?if($cur_page-1>=0){?>
    <a href='?page=<?=$cur_page-1?>'><</a> | 
    <?
    }
    for($i=$start_page_pagination;$i<=$end_page_pagination;$i++)
    {
      $style="";
      $i1=$i+1;
      if($i==$cur_page)
        $style="style='color:red;'";
      
      echo "<a href='?page=$i' $style> $i1</a> | ";
    }
    
    if($cur_page+1<$page_count-1)
      {
      ?>
      <a href='?page=<?=$cur_page+1?>'>></a> | 
    <?}?>
    <a href='?page=<?=$page_count-1?>'>>></a> 
    

     

  • Настройка ретрансляции rtsp на вебсайт с ffmpeg

    1. Устанавливаем  ffmpeg
    2. Заходим в etc/ffserver.conf и добавляем в конец
      <Feed monitoring1.ffm>
      ACL allow localhost
      ACL allow 192.168.0.0 192.168.255.255
      File /tmp/monitoring1.ffm
      FileMaxSize 50M
      ACL allow 127.0.0.1
      </Feed>
      
      <Stream monitoring1.mjpg>
      Feed monitoring1.ffm
      Format mpjpeg
      VideoCodec mjpeg
      VideoFrameRate 22
      VideoBufferSize 80
      VideoSize 720x264
      NoAudio
      </Stream>
      
    3. Запускаем сервер
      ffserver -d -f /etc/ffserver.conf
    4. Запускаеми перекодировку
      ffmpeg -i «rtsp://192.168.0.100:554/onvif1» «http://127.0.0.1:8090/monitoring1.ffm»
    5. Наблюдаем результат. Открываем страничку в бразуере http://localhost:8090/monitoring1.mjpg
    6. Должна появиться картинка.
  • Примеры решения заданий по 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
    

  • Интерактивное обновление данных используя AJAX

    index.php

    <link rel=»stylesheet» href=»https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css»><link rel=»stylesheet» href=»https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css»>  <script src=»https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js»></script>  <script src=»https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js»></script>  <script type=»text/javascript»>function loadXMLDoc(q) {     var xmlhttp = new XMLHttpRequest();    xmlhttp.onreadystatechange = function() {        if (xmlhttp.readyState == XMLHttpRequest.DONE) {   //            if (xmlhttp.status == 200 && xmlhttp.readyState==4) {               document.getElementById(«mydiv»).innerHTML = xmlhttp.responseText;           }        }    };    xmlhttp.open(«GET», «ajax/getfruit.php?q=»+q, true);    xmlhttp.send();}
    function save_fruit(id,text) {     var xmlhttp = new XMLHttpRequest();    xmlhttp.onreadystatechange = function() {        if (xmlhttp.readyState == XMLHttpRequest.DONE) {   //            if (xmlhttp.status == 200 && xmlhttp.readyState==4) {                         }        }    };    xmlhttp.open(«GET», «ajax/savefruit.php?id=»+id+»&text=»+text, true);    xmlhttp.send();}</script><input onkeyup=»loadXMLDoc(this.value)»>
    <?
    mysql_connect(«localhost»,»root»,»»);mysql_select_db(«ajax»);$_GET[‘q’]=urldecode($_GET[‘q’]);$data=mysql_query(«select * from `fruits`»);while($res=mysql_fetch_array($data)) { echo «<div id=’id_{$res[‘id’]}’ data-toggle=’modal’ onclick=’setdata(\»{$res[‘fruit’]}\»,\»{$res[‘id’]}\»)’ data-target=’#myModal’ class=’btn btn-success’>».$res[‘fruit’].»</div>»; }?>
    <div class=»container»>
    <!— Trigger the modal with a button —>
    <!— Modal —>  <div class=»modal fade» id=»myModal» role=»dialog»>    <div class=»modal-dialog»>          <!— Modal content—>      <div class=»modal-content»>        <div class=»modal-header»>          <button type=»button» class=»close» data-dismiss=»modal»>&times;</button>          <h4 class=»modal-title»>Введите имя нового фрукта</h4>        </div>        <div class=»modal-body»> <p> <input id=’fruit’ placeholder=»Введите имя фрукта»> <input id=’fruitid’ type=’hidden’> </p>        </div>        <div class=»modal-footer»>          <button type=»button» class=»btn btn-success» onclick=»save()»>Сохранить</button>   <button type=»button» class=»btn btn-default» data-dismiss=»modal»>Закрыть</button>        </div>      </div>          </div>  </div>  </div><script>function save(){ text=document.getElementById(«fruit»).value; id=document.getElementById(«fruitid»).value; document.getElementById(«id_»+id).innerHTML=text; save_fruit(id,text); $(‘#myModal’).modal(‘hide’); }function setdata(text,id){ document.getElementById(«fruit»).value=text; document.getElementById(«fruitid»).value=id;}</script>

     

    savefruit.php

     

    <?
    mysql_connect(«localhost»,»root»,»»);
    mysql_select_db(«ajax»);
    mysql_query(«update `fruits` set `fruit`='{$_GET[‘text’]}’ where `id`='{$_GET[‘id’]}’»);

    ?>

     

     

  • Задачи на массивы.

    Задачи на массивы.

    Задания на одномерные массивы.
    1. Заполнить массив числами от 1 до 100 и вывести его в консоль.
    2. Заполнить массив числами от 100 до 1 и вывести его в консоль.
    3. Заполнить массив числами от -50 до 50 и вывести его в консоль.
    4. Заполнить массив случайными числами и вывести его в консоль.
    5. Заполнить массив случайными числами и найти максимальное значение.
    6. Заполнить массив случайными числами и найти минимальное значение.
    7. Заполнить массив случайными числами и удалить из него все элементы в которых записано число 2.
    8. Заполнить массив случайными числами и выполнить его сортировку.
    9. Заполнить массив случайными числами и найти в нем все значения которые повторяются более одного раза.
    10. Заполнить два массива случайными числами и найти значения которые не повторяются в обоих массивах. Если число находится в обоих массивах то его не нужно выводить. Вывести нужно только те значения которые есть только в одном массиве.
    Задания на двумерные массивы.

    1. Создать двумерный массив и заполнить в его ячейки таблицу умножения.
    2. Создать двумерный массив и заполнить две его диагонали единицами.
    3. Создать двумерный массив и заполнить его рамочку единицами.
    4. Решить задачу о 8ми ферзях. Широко известная задача по расстановке фигур на шахматной доске. Исходная формулировка: «Расставить на стандартной 64-клеточной шахматной доске 8 ферзей так, чтобы ни один из них не находился под боем другого». Подразумевается, что ферзь бьёт все клетки, расположенные по вертикалям, горизонталям и обеим диагоналям.
    5. Решить обобщенную задачу о ферзях. Расставить максимальное количество взаимно не бьющих друг друга ферзей на прямоугольном поле, в частности, квадратном поле, со стороной n.

     

  • Задания на циклы

    Задания на циклы

    Задание:

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

     

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

    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
    

  • Задания на операторы сравнения

    Задания на операторы сравнения

    Операторы сравнения

    Большинство операторов сравнения применимы к числовым значениям. Всё это бинарные операторы, имеющие два числовых аргумента, но возвращающие логическое значение.

    • > — оператор «больше».
    • >= — оператор «больше или равно».
    • < — оператор «меньше».
    • <= — оператор «меньше или равно».
    • != — оператор «не равно».
    • == — оператор эквивалентности (равенства).
    1. Создать программу, проверяющую и сообщающую на экран, является ли целое число записанное в переменную n, чётным либо нечётным.
    2. Создать программу, выводящую на экран ближайшее к 10 из двух чисел, записанных в переменные m и n. Например, среди чисел 8,5 и 11,45 ближайшее к десяти 11,45.
    3. В три переменные a, b и c записаны три вещественных числа. Создать программу, которая будет находить и выводить на экран вещественные корни квадратного уравнения ax²+bx+c=0, либо сообщать, что корней нет.
    4. Написать программу преобразования цифр в слова.
    5. Написать программу которая найдет максимальное число из двух.
    6. Написать программу которая найдет максимальное число из трех.
    7. Написать программу которая найдет максимальное число из четырех.
    8. В три переменные a, b и c явно записаны программистом три целых попарно неравных между собой числа. Создать программу, которая переставит числа в переменных таким образом, чтобы при выводе на экран последовательность a, b и c оказалась строго возрастающей.
    9. Вывести таблицу истинности для оператора and
    10. Вывести таблицу истинности для оператора or
    11. Написать тест на знание таблицы умножения
    12. Написать тест на проверку сложения чисел до 100