Advertisement
Velja_Programer

Kraljica by Velja

Apr 11th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int main(int argc, char *argv[]) {
  7.     int x,y,j,i,kx,ky;
  8.     printf("Unesite velicinu sahovske table po X i Y osi:");
  9.     scanf("%d %d",&x,&y);
  10.     char niz[x][y];
  11.     for(i=0;i<x;i++)
  12.         for(j=0;j<y;j++)
  13.         {
  14.             niz[i][j]='-';
  15.         }
  16. for(i=0;i<x;i++)
  17. {
  18.  
  19.         for(j=0;j<y;j++)
  20.         {
  21.             printf("%c ",niz[i][j]);
  22.         }
  23.         printf("\n");
  24. }
  25.     printf("Unesite kordinate kraljice X i Y \n");
  26.     scanf("%d %d",&kx,&ky);
  27.     for(i=0;i<x;i++)
  28.         for(j=0;j<y;j++)
  29.         {
  30.             if(abs(i-kx)==abs(j-ky))
  31.             {
  32.                 niz[i][j]='*';
  33.             }
  34.         }
  35.         niz[kx][ky]='K';
  36.         int a,b;
  37.         a=kx;
  38.         b=ky;
  39.         while(a<=x)
  40.         {
  41.             niz[a][b]='*';
  42.             a++;
  43.         }
  44.         a=kx;
  45.         b=ky;
  46.         while(b<x)
  47.         {
  48.             niz[a][b]='*';
  49.             b++;
  50.         }
  51.         a=kx;
  52.         b=ky;
  53.         while(a>-1)
  54.         {
  55.             niz[a][b]='*';
  56.             a--;
  57.         }
  58.             a=kx;
  59.         b=ky;
  60.         while(b>-1)
  61.         {
  62.             niz[a][b]='*';
  63.             b--;
  64.         }
  65.        
  66.        
  67.         niz[kx][ky]='K';
  68.        
  69.    
  70.         for(i=0;i<x;i++)
  71. {
  72.  
  73.         for(j=0;j<y;j++)
  74.         {
  75.             printf("%c ",niz[i][j]);
  76.         }
  77.         printf("\n");
  78. }
  79.    
  80.  
  81.  
  82.  
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement