Contact Learn C
Copy

Program 50:Symbol Pattern 3

Program 50:
 
#include<stdio.h>
main()
{
    int i,j,num;
    printf("Enter number of rows\n");
    scanf("%d",&num);
    for(i=num;i>=1;i--)
    {
    
        for(j=i;j>=1;j--)
        {
            printf("*");
           
        }
        
    printf("\n");
    }
}
Explanation:

  1. The program starts with initializing
    • num → To store number of rows
    • i ,jTemporary variable
  2. printf("Enter number of rows\n");
     scanf("%d",&num);
    Taking number of rows from user.
  3. Main Logic goes here:
    for(i=num;i>=1;i--)
        {
        
            for(j=i;j>=1;j--)
            {
                printf("*");
               
            }
            
        printf("\n");
        }
  4. Lets take number of rows be 3.So num=3
    • Iteration 1 of First Loop:i=num→i=3 and i>=1 which is true so 1st Loop execute
      • Iteration 1 of 2nd Loop:j=i→j=3 and j>=1 which is true so iteration continues
        • And prints '*' in 1st row and 1st coumn
        • Now  will be decremented by 1
        • So now j=2
      • Iteration 2 of 2nd Loop:j=2 and j>=1  which is true so iteration continues
        • And prints '*' in 1st row and 2nd coumn
        • Now  will be decremented by 1
        • So now j=1
      • Iteration 3 of 2nd Loop:j=1 and j>=1 which is true so iteration continues
        • And prints '*' in 1st row and 3rd coumn
        • Now  will be decremented by 1
        • So now j=0
      • Iteration 4 of 2nd Loop:j=0 and j>=1 which is false so 2nd loop terminates
      • So till now 1st row is printed
    • Iteration 2 of First Loop:i=2 and i>=1 which is true so 1st Loop execute
      • Iteration 1 of 2nd Loop:j=i→j=2 and j>=1 which is true so iteration continues
        • And prints '*' in 2nd row and 1st coumn
        • Now  will be decremented by 1
        • So now j=1
      • Iteration 2 of 2nd Loop:j=1 and j>=1  which is true so iteration continues
        • And prints '*' in 2nd row and 2nd coumn
        • Now  will be decremented by 1
        • So now j=0
      • Iteration 3 of 2nd Loop:j=0 and j>=1 which is false so 2nd loop terminates
      • So till now 1st row and 2nd row are printed
    • Iteration 3 of First Loop:i=1 and i>=1 which is true so 1st Loop execute
      • Iteration 1 of 2nd Loop:j=i→j=1 and j>=1 which is true so iteration continues
        • And prints '*' in 3rd row and 1st coumn
        • Now  will be decremented by 1
        • So now j=0
      • Iteration 2 of 2nd Loop:j=0 and j>=1 which is false so 2nd loop terminates
      • So all the 3 rows are printed
    • Iteration 4 of First loop:i=0 and i>=1 is false so First Loop also terminates


 Output:

Symbol Pattern 3
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide