Advertisement
Mr_kindle

starbarfi.c

Dec 9th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | Source Code | 0 0
  1. /*
  2.     Name: starbarfi.c
  3.     Copyright:
  4.     Author: Mr.Kindle (youtube: Mr_Kindle)
  5.     Date: 30-11-22 23:13
  6.     Description: this code print following number of patterns if number of rows = 4.
  7.                    *
  8.                    **
  9.                   ***
  10.                    **
  11.                     *
  12.  
  13. YOUTUBE:https://youtu.be/mIXF8x0FV_c
  14.                
  15. */
  16.  
  17.  
  18. #include <stdio.h>
  19. int main()
  20. {
  21.   int n, c, k,j,flag;
  22.  
  23.   printf("Enter number of rows (less than 9 for better result)\n");
  24.   scanf("%d", &n);
  25. /*First make upper triangle*/
  26.  
  27.   for (k=1; k<=n; k++)
  28.   {     /*for printing the spaces*/
  29.         for (c=1; c<=n-k; c++)
  30.             printf(" ");
  31.        
  32.         j=k;// so that the value of 'k' doesnot alter.
  33.        
  34.        
  35.         /*for printing the numbers*/
  36.        
  37.         /*there are '2k - 1' number of element in each 'kth' row.*/
  38.         for (c = 1; c <= 2*k-1; c++)
  39.             {  
  40.                 printf("*");
  41.    
  42.              }
  43.  
  44.         printf("\n");
  45.   }//for loop for upper triangle
  46.  
  47.   /*making lower inverse triangle*/
  48.  
  49.     for (k=1; k<=n-1; k++)//we will print 1 line less hence 'k<=n-1' instead of 'k<=n.
  50.         {
  51.    
  52.             for (c=1; c<=k; c++)
  53.                 printf(" ");
  54.                
  55.             j=n-k;
  56.          
  57.  
  58.             for (c=1 ; c<=2*(n-k)-1; c++)
  59.                 {  
  60.                     printf("*");
  61.                 }
  62.  
  63.             printf("\n");
  64.         }
  65.  
  66.     return 0;
  67. }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement