Home / Programs / C program to print the given star pattern. * ** *** **** *****
🚀 Programming Example

C program to print the given star pattern.
*
**
***
****
***** 

👁 2,519 Views
💻 Practical Program
📘 Step Learning
C program to print the given star pattern.

💻 Program Code

#include "stdio.h"
int main()
{
    int i=1,j;
    do
    {
        j=1;
        do
        {
            printf("*");
            j++;
        }while(j <= i);
        i++;
        printf("\n");
    }while(i <= 5);
    return 0;
}
                        

🖥 Program Output

*
**
***
****
*****
Press any key to continue . . .
                            

📘 Explanation

In this program, the nested do-while loop is used to print the star pattern. The outermost loop runs 5 times and for every loop, the innermost loop runs i times which is 1 at first, meaning only one "*" is printed, then on the next loop it's 2 printing two stars and so on till 5 iterations of the loop executes, printing five stars. This way, the given star pattern is printed.
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.