dry run for the given code ?

+2 votes
asked Sep 23, 2019 by anonymous
/*explanation in brief*/
#include <stdio.h>

int main()
{
    int i, j, rows;

    /* Input rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);

    /* Iterate through rows */
    for(i=1; i<=rows; i++)
    {
        /* Print spaces in decreasing order of row */
        for(j=i; j<rows; j++)
        {
            printf(" ");
        }

        /* Print star in increasing order or row */
        for(j=1; j<=i; j++)
        {
            printf("*");
        }

        /* Move to next line */
        printf("\n");
    }
    
    return 0;
}

1 Answer

0 votes
answered Sep 24, 2019 by anonymous
1. User enters number of rows

2. Checks if first for condition is true. Moves to next for loop.

3. Adds whitespace until condition is false. Moves to next for loop.

4. Prints * until condition is false.

5. Prints new line

6. Repeat stages 2-6 until stage 2 is false.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...