Number Patterns for C, Java, and Python Programming

Learn how to create popular number patterns with step-by-step solutions in C, Java, and Python programming languages.24 min


number patterns in c with examples interview

For your interview preparation, I created all-in-one solutions for different varieties of number patterns in C, Java, and Python.

1. Pattern: Descending Number Triangle

Expected output:

12345
1234
123
12
1

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows
    for (int i = 5; i >= 1; i--) {
        // Inner loop for printing numbers from 1 to i
        for (int j = 1; j <= i; j++) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows
        for (int i = 5; i >= 1; i--) {
            // Inner loop for printing numbers from 1 to i
            for (int j = 1; j <= i; j++) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows
for i in range(5, 0, -1):
    # Inner loop for printing numbers from 1 to i
    for j in range(1, i + 1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

2. Pattern: Descending Number Triangle

Expected output:

54321
4321
321
21
1

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 5 down to 1)
    for (int i = 5; i >= 1; i--) {
        // Inner loop to print numbers from i down to 1
        for (int j = i; j >= 1; j--) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 5 down to 1)
        for (int i = 5; i >= 1; i--) {
            // Inner loop to print numbers from i down to 1
            for (int j = i; j >= 1; j--) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 5 down to 1)
for i in range(5, 0, -1):
    # Inner loop to print numbers from i down to 1
    for j in range(i, 0, -1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

3. Pattern: Descending Number Triangle (Modified)

Expected output:

12345
2345
345
45
5

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print numbers starting from i to 5
        for (int j = i; j <= 5; j++) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print numbers starting from i to 5
            for (int j = i; j <= 5; j++) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print numbers starting from i to 5
    for j in range(i, 6):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

4. Pattern: Descending Number Triangle (Modified)

Expected output:

54321
5432
543
54
5

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 5 down to 1)
    for (int i = 5; i >= 1; i--) {
        // Inner loop to print numbers starting from 5 down to i
        for (int j = 5; j >= 6 - i; j--) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 5 down to 1)
        for (int i = 5; i >= 1; i--) {
            // Inner loop to print numbers starting from 5 down to i
            for (int j = 5; j >= 6 - i; j--) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 5 down to 1)
for i in range(5, 0, -1):
    # Inner loop to print numbers starting from 5 down to i
    for j in range(5, 6 - i, -1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

5. Pattern: Ascending Number Triangle

Expected output:

1
21
321
4321
54321

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print numbers starting from i down to 1
        for (int j = i; j >= 1; j--) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print numbers starting from i down to 1
            for (int j = i; j >= 1; j--) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print numbers starting from i down to 1
    for j in range(i, 0, -1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

6. Pattern: Ascending Number Triangle

Expected output:

1
12
123
1234
12345

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print numbers from 1 to i
        for (int j = 1; j <= i; j++) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print numbers from 1 to i
            for (int j = 1; j <= i; j++) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print numbers from 1 to i
    for j in range(1, i + 1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

7. Pattern: Descending Number Triangle (Modified)

Expected output:

5
54
543
5432
54321

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print numbers starting from 5 down to (5 - i + 1)
        for (int j = 5; j >= 6 - i; j--) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print numbers starting from 5 down to (5 - i + 1)
            for (int j = 5; j >= 6 - i; j--) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print numbers starting from 5 down to (5 - i + 1)
    for j in range(5, 6 - i, -1):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

8. Pattern: Modified Ascending Number Triangle

Expected output:

5
45
345
2345
12345

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 5; i >= 1; i--) {
        // Inner loop to print numbers starting from i to 5
        for (int j = i; j <= 5; j++) {
            printf("%d", j); // Print the current number
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 5 down to 1)
        for (int i = 5; i >= 1; i--) {
            // Inner loop to print numbers starting from i to 5
            for (int j = i; j <= 5; j++) {
                System.out.print(j); // Print the current number
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 5 down to 1)
for i in range(5, 0, -1):
    # Inner loop to print numbers starting from i to 5
    for j in range(i, 6):
        print(j, end='')  # Print the current number, stay on the same line
    print()  # Move to the next line after each row

9. Pattern: Repetitive Number Triangle

Expected output:

1
22
333
4444
55555

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 1 to 5)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print the number i, i times
        for (int j = 1; j <= i; j++) {
            printf("%d", i); // Print the current number i
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print the number i, i times
            for (int j = 1; j <= i; j++) {
                System.out.print(i); // Print the current number i
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print the number i, i times
    for j in range(i):
        print(i, end='')  # Print the current number i, stay on the same line
    print()  # Move to the next line after each row

10. Pattern: Descending Repetitive Number Triangle

Expected output:

55555
4444
333
22
1

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 5 to 1)
    for (int i = 5; i >= 1; i--) {
        // Inner loop to print the number i, i times
        for (int j = 1; j <= i; j++) {
            printf("%d", i); // Print the current number i
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 5 down to 1)
        for (int i = 5; i >= 1; i--) {
            // Inner loop to print the number i, i times
            for (int j = 1; j <= i; j++) {
                System.out.print(i); // Print the current number i
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 5 down to 1)
for i in range(5, 0, -1):
    # Inner loop to print the number i, i times
    for j in range(i):
        print(i, end='')  # Print the current number i, stay on the same line
    print()  # Move to the next line after each row

11. Pattern:

Expected output:

5
44
333
2222
11111

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 5 down to 1)
    for (int i = 5; i >= 1; i--) {
        // Inner loop to print the number i, i times
        for (int j = 1; j <= i; j++) {
            printf("%d", i); // Print the current number i
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 5 down to 1)
        for (int i = 5; i >= 1; i--) {
            // Inner loop to print the number i, i times
            for (int j = 1; j <= i; j++) {
                System.out.print(i); // Print the current number i
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 5 down to 1)
for i in range(5, 0, -1):
    # Inner loop to print the number i, i times
    for j in range(i):
        print(i, end='')  # Print the current number i, stay on the same line
    print()  # Move to the next line after each row

12. Pattern: Descending Repetitive Number Triangle (Modified)

Expected output:

11111
2222
333
44
5

Solution in C Program:

#include <stdio.h>

int main() {
    // Outer loop for the number of rows (starting from 5 down to 1)
    for (int i = 1; i <= 5; i++) {
        // Inner loop to print the number i, 6 - i times
        for (int j = 1; j <= 6 - i; j++) {
            printf("%d", i); // Print the current number i
        }
        printf("n"); // Move to the next line after each row
    }
    return 0;
}

Solution in Java:

public class NumberPattern {
    public static void main(String[] args) {
        // Outer loop for the number of rows (starting from 1 to 5)
        for (int i = 1; i <= 5; i++) {
            // Inner loop to print the number i, 6 - i times
            for (int j = 1; j <= 6 - i; j++) {
                System.out.print(i); // Print the current number i
            }
            System.out.println(); // Move to the next line after each row
        }
    }
}

Solution in Python:

# Outer loop for the number of rows (starting from 1 to 5)
for i in range(1, 6):
    # Inner loop to print the number i, 6 - i times
    for j in range(6 - i):
        print(i, end='')  # Print the current number i, stay on the same line
    print()  # Move to the next line after each row

Hope you find them helpful for your interview preparation in a good way.

©️ 2025, Number patterns in C, Java, and Python programming language by Rakshit Shah (Author).

You may also like,

1. Alphabet Patterns — Java, Python, and C program
Learn how to code different alphabet patterns in Java, Python, and C Programming
.

2. Check Pair of Brackets (Well-Formatted) in an Expression
A simple program to check the pair of brackets using Stack in Java, Python, and C#.

3. Hard Number Patterns in C, Java, and Python Programming [Interview Questions]

adsense


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
0
Cute
Love Love
0
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
0
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Legend

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

0 Comments

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment