Lisaveta777

Print triangles

Nov 4th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define WIDE 15
  4. #define HIGH 9
  5. #define SIZE 5
  6.  
  7. //печать 4 одинаковых равносторонних прямоугольных треугольников(каждый из них уникальным образом развернут)
  8. //с отступом сверху и слева, введенным с клавиатуры
  9.  
  10. void pr_stars(int,int,int,int,int,int);//top_gap,left_gap,HIGH,WIDE,SIZE,formula clue
  11.  
  12. int main()
  13. {
  14.    int i,j,arr[HIGH][WIDE],top_gap,left_gap,sum=0;
  15.    printf("Enter (0-3) rows_gap,cols_gap: ");
  16.    scanf("%d %d",&top_gap,&left_gap);
  17.  
  18.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,1);//last argument is a clue for triangle form specification
  19.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,2);
  20.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,3);
  21.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,4);
  22.        
  23.  
  24.     return 0;
  25. }
  26.  
  27. void pr_stars(int t,int l,int h,int w,int s ,int clue)
  28. {
  29.     int i,j,start,finish;
  30.     for(i=0;i<h;i++)//1  1 star + 9 spaces
  31.    {
  32.        if(i<t||i>=t+s)
  33.             {
  34.                 for(j=0;j<w;j++)
  35.                     printf("+");
  36.                 printf("\n");
  37.             }
  38.        else
  39.         {
  40.             for(j=0;j<w;j++)
  41.             {
  42.                 switch(clue)//to set start and finish depending of clue
  43.                 {
  44.                     case 1: start = l;finish = l-t+i+1;break;
  45.                     case 2: start = l;finish = l+t+s-i;break;
  46.                     case 3: start = l+t+s-i-1;finish = l+s;break;
  47.                     case 4: start = l-t+i; finish = l+s;break;
  48.                 }
  49.                 printf("%c",(j>=start&&j<finish)?'*':'-');//
  50.             }
  51.         printf("\n");
  52.  
  53.         }//end of else
  54.    }
  55. }
Add Comment
Please, Sign In to add comment