Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: starbarfi.c
- Copyright:
- Author: Mr.Kindle (youtube: Mr_Kindle)
- Date: 30-11-22 23:13
- Description: this code print following number of patterns if number of rows = 4.
- *
- **
- ***
- **
- *
- YOUTUBE:https://youtu.be/mIXF8x0FV_c
- */
- #include <stdio.h>
- int main()
- {
- int n, c, k,j,flag;
- printf("Enter number of rows (less than 9 for better result)\n");
- scanf("%d", &n);
- /*First make upper triangle*/
- for (k=1; k<=n; k++)
- { /*for printing the spaces*/
- for (c=1; c<=n-k; c++)
- printf(" ");
- j=k;// so that the value of 'k' doesnot alter.
- /*for printing the numbers*/
- /*there are '2k - 1' number of element in each 'kth' row.*/
- for (c = 1; c <= 2*k-1; c++)
- {
- printf("*");
- }
- printf("\n");
- }//for loop for upper triangle
- /*making lower inverse triangle*/
- for (k=1; k<=n-1; k++)//we will print 1 line less hence 'k<=n-1' instead of 'k<=n.
- {
- for (c=1; c<=k; c++)
- printf(" ");
- j=n-k;
- for (c=1 ; c<=2*(n-k)-1; c++)
- {
- printf("*");
- }
- printf("\n");
- }
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement