SuitNdtie

programming.in.th 0022 : ดาว (star)

Oct 6th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n;
  6.     scanf("%d",&n);
  7.     if(n%2==1)//ki-
  8.     {
  9.         int fs = n/2,ls = n/2;
  10.         for(int i=0;i<n;i++)
  11.         {
  12.             for(int j=0;j<n;j++)
  13.             {
  14.                 if(j==fs || j==ls)printf("*");
  15.                 else printf("-");
  16.             }
  17.             printf("\n");
  18.             if(i<n/2)
  19.             {
  20.                 fs--;
  21.                 ls++;
  22.             }
  23.             else
  24.             {
  25.                 fs++;
  26.                 ls--;
  27.             }
  28.         }
  29.     }
  30.     else//ku-
  31.     {
  32.         int fs = n/2 -1,ls = n/2 -1;
  33.         for(int i=0;i<n;i++)
  34.         {
  35.             for(int j=0;j<n-1;j++)
  36.             {
  37.                 if(j==fs || j==ls)printf("*");
  38.                 else printf("-");
  39.             }
  40.             printf("\n");
  41.             if(i<n/2 - 1)
  42.             {
  43.                 fs--;
  44.                 ls++;
  45.             }
  46.             else if (i>n/2 - 1)
  47.             {
  48.                 fs++;
  49.                 ls--;
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment