Pattern Programming Dashboard
Pattern Programming Questions with Solutions
Suppose you are asked two questions in the online test. Atleast one of the two questions that you will be asked will be pattern printing program.
There are only limited number of coding pattern programs in the world on this dashboard you will find all of the pattern printing programs possible.
Thus, in your exam you should get one of the program from below:
What is a pattern in programming?
Star pattern programming is a basic concept in programming where we print shapes or patterns using asterisks (*). These patterns can be simple or complex depending on the logic used.
It is widely used to:
- Understand loops (for/while)
- Learn nested loop concepts
- Improve logical thinking and problem-solving skills
There are 2 types of Coding(pattern) programs:
- Star based Printing – Click here to visit this section
- Number based Pattern – Click here to visit this section
- Star-Number Mixed Pattern – Click here to visit this section
Understanding the Core Logic:
All star patterns are based on two main components:
- Rows → controlled by the outer loop
- Columns (stars per row) → controlled by the inner loop
The idea is simple:
Right Angled Triangle Pattern
Output:
*
* *
* * *
* * * *
* * * * *
Code:
#include <stdio.h>
int main() {
int n;
printf("Enter number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) { // Rows
for (int j = 1; j <= i; j++) { // Stars
printf("* ");
}
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: "; cin >> n;
for (int i = 1; i <= n; i++) { // Rows
for (int j = 1; j <= i; j++) { // Stars
cout << "* ";
}
cout << endl;
}
return 0;
}
import java.util.Scanner;
public class StarPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) { // Rows
for (int j = 1; j <= i; j++) { // Stars
System.out.print("* ");
}
System.out.println();
}
}
}
import java.util.Scanner;
public class StarPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) { // Rows
for (int j = 1; j <= i; j++) { // Stars
System.out.print("* ");
}
System.out.println();
}
}
}
2. The outer loop runs from 1 to n to control rows.
3. The inner loop runs from 1 to the current row number.
4. Each iteration prints a star followed by a space.
5. After each row, a new line is printed.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Star Pattern Printing Programs
Number Pattern Printing Programs
Number Star Mix Pattern
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Login/Signup to comment