Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. // sierp2.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <amp_math.h>
  8. using namespace std;
  9. int w = 32;
  10. string **A;
  11. void sierp(int x1, int y1, int x2, int y2, int x3, int y3, int depth) {
  12.  if (depth == 1) return;
  13.  else {
  14.      int s = 0;
  15.      for (int i = x1 + 1; i < (x1 + x3) / 2; i++) {
  16.          s += 1;
  17.          for (int j = ((y2 + y1) / 2); j <= ((y3 + y1) / 2) + s - 1; j++) {
  18.              A[i][j] = " ";
  19.          }
  20.      }sierp((x2+x1)/2, y1, (x2+x1)/2, (y2 + y1) / 2, (x3 + x1) / 2, (y3 + y1) / 2, depth - 1);
  21.      sierp((x2 + x1) / 2, (y2+y1)/2, (x2 + x1) / 2, y2, (x3 + x1) / 2, (y3 + y2) / 2, depth - 1);
  22.      sierp((x1 + x3) / 2, (y1 + y3) / 2, (x2 + x3) / 2, (y3 + y2) / 2, x3, y3, depth - 1);
  23.  }
  24.     return;
  25. }
  26.  
  27. int main() {
  28.    
  29.  
  30.     //+1 tak aby na wszelki wypadek był jeden wymiar wiecej
  31.     A = new string *[w + 1];
  32.     for (int i = 0; i <= w + 1; i++) {
  33.         A[i] = new string[w];
  34.     }
  35.  
  36.     //tworzymy macierz 16x16
  37.     for (int i = 0; i < w; i++) {
  38.         for (int j = 0; j < w; j++) {
  39.             A[i][j] = " ";
  40.         }
  41.     }
  42.  
  43.     //tworzymy trojkat
  44.     for (int i = 0; i < w; i++) {
  45.         for (int j = i; j < w; j++) {
  46.             A[i][j] = "*";
  47.         }
  48.     }
  49.     sierp(0, 0, 0, w, w, w, 7);
  50.    
  51.     //pokazujemy wynik
  52.     for (int i = 0; i < w; i++) {
  53.         for (int j = 0; j < w; j++) {
  54.             cout << A[i][j];
  55.         }
  56.         cout << endl;
  57.     }
  58.     for (int x = 0; x < w; x++)
  59.     {
  60.         delete[] A[x];
  61.     }
  62.  
  63.     delete[] A;
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement