Guest User

Untitled

a guest
May 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void rysuj(int);
  4. int bezwzgledna(int);
  5. using namespace std;
  6.  
  7. int bezwzgledna(int a){
  8.     if(a<0){
  9.         a=-a;
  10.     }
  11.     return a;
  12. }
  13.  
  14. void rysuj(int bok){
  15.     int korekta=bok/2;
  16.     //int korekta_wymiaru=1;
  17.     if(bok%2==1){
  18.         korekta=(bok-1)/2;
  19.         //korekta_wymiaru=0;
  20.     }
  21.  
  22.     for(int y=-(bok-1); y<(bok-1)+1; y++){
  23.         for(int x=-(bok+korekta-1); x<(bok+korekta); x++){
  24.             if(bezwzgledna(x+bok+korekta-1)==bezwzgledna(y) or bezwzgledna(x-bok-korekta+1)==bezwzgledna(y))
  25.             {
  26.                 cout<<"*";
  27.             }
  28.             else if((bezwzgledna(y)==(bok-1)) and bezwzgledna(x)<=korekta)
  29.             {
  30.                 cout<<"x";
  31.                 if(bok%2==0 and x==1){
  32.                     cout<<"\b";
  33.                 }
  34.             }
  35.             else if(bok%2==0 and x==1){
  36.                 cout<<"";
  37.             }
  38.             else
  39.             {
  40.                 cout<<" ";
  41.             }
  42.         }
  43.         cout<<endl;
  44.     }
  45.  
  46.  
  47. }
  48.  
  49. int main()
  50. {
  51.     int bok=1;
  52.     while(bok>0){
  53.         cout<<"Podaj bok(0 konczy program): ";
  54.         cin>>bok;
  55.         bok=bezwzgledna(bok);
  56.         rysuj(bok);
  57.     }
  58.     return 0;
  59. }
Add Comment
Please, Sign In to add comment