Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

Hourglass Pattern in C: Star, Number, Alphabet & Binary Patterns with Output

⭐ C Program to Print Inverted and Right-Side Up Repeated Binary Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",i%2);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",i%2);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 1 1 1 1 1
  0 0 0 0
   1 1 1
    0 0
     1
     1
    0 0
   1 1 1
  0 0 0 0
 1 1 1 1 1
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up repeated binary triangle diamond pattern using nested for loops. The first outer loop generates the upper inverted triangle by decreasing the number of columns in each row, while the second outer loop creates the lower triangle by increasing the number of columns. The inner loop prints the value of i % 2, so every row contains the same binary digit. Odd-numbered rows display 1, and even-numbered rows display 0, resulting in a symmetric repeated binary diamond pattern.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the upper inverted binary triangle.
  3. Print the required leading spaces before each row.
  4. Use an inner loop to print the value of i % 2 repeatedly across the current row.
  5. Repeat the same process with another outer loop from 1 to num to print the lower half of the repeated binary diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up repeated binary triangle diamond pattern in C using nested loops. This C program demonstrates modulus operator usage, nested loops, spacing logic, repeated binary values, and diamond pattern generation.

πŸ” Keywords

Repeated Binary Diamond Pattern in C, Binary Pattern Printing in C, Binary Triangle Pattern, Nested Loops in C, Modulus Operator Pattern, C Programming Examples, Repeated Binary Pattern, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #BinaryPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Binary Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j%2);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j%2);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 1 0 1 0 1
  1 0 1 0
   1 0 1
    1 0
     1
     1
    1 0
   1 0 1
  1 0 1 0
 1 0 1 0 1
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up binary triangle diamond pattern using nested for loops. The first outer loop creates the upper inverted triangle by decreasing the number of columns in each row. The second outer loop builds the lower triangle by increasing the number of columns. The inner loop uses the expression j % 2 to print alternating binary values 1 and 0 across each row, creating a symmetrical binary diamond pattern.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the upper inverted binary triangle.
  3. Print leading spaces before each row for proper alignment.
  4. Use an inner loop to print alternating binary values using j % 2.
  5. Repeat the same logic with another outer loop from 1 to num to print the lower half of the binary diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up binary triangle diamond pattern in C using nested loops. This beginner-friendly C program demonstrates alternating binary values, nested loops, spacing logic, and pattern generation techniques.

πŸ” Keywords

Binary Diamond Pattern in C, Binary Triangle Pattern C, Pattern Printing in C, Nested Loops in C, Alternating Binary Pattern, C Programming Examples, Binary Pattern Program, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #BinaryPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Repeated Alphabet Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%c ",i+64);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%c ",i+64);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 E E E E E
  D D D D
   C C C
    B B
     A
     A
    B B
   C C C
  D D D D
 E E E E E
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up repeated alphabet triangle diamond pattern using nested for loops. The first outer loop creates the inverted triangle by decreasing the number of characters in each row, while the second outer loop builds the lower triangle by increasing the number of characters. Instead of printing sequential alphabets, the program prints the same alphabet repeatedly in each row by converting the current row number (i + 64) into its corresponding uppercase ASCII character.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the upper inverted alphabet triangle.
  3. Print the required leading spaces before each row.
  4. Use an inner loop to print the same alphabet repeatedly by converting i + 64 into its corresponding ASCII character.
  5. Repeat the same process with another outer loop from 1 to num to print the lower half of the repeated alphabet diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up repeated alphabet triangle diamond pattern in C using nested loops. This C program demonstrates ASCII character conversion, nested loops, spacing logic, repeated alphabet printing, and diamond pattern generation.

πŸ” Keywords

Repeated Alphabet Diamond Pattern in C, Alphabet Pattern Printing in C, ASCII Character Pattern, Nested Loops in C, Character Diamond Pattern, C Programming Examples, Repeated Alphabet Pattern, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #AlphabetPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Alphabet Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%c ",j+64);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%c ",j+64);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 A B C D E
  A B C D
   A B C
    A B
     A
     A
    A B
   A B C
  A B C D
 A B C D E
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up alphabet triangle diamond pattern using nested for loops. The first outer loop generates the inverted alphabet triangle by decreasing the number of characters in each row, while the second outer loop creates the lower triangle by increasing the number of characters. The inner loop converts numbers into uppercase alphabets using the ASCII expression j + 64, resulting in letters from A onward.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the upper inverted alphabet triangle.
  3. Print leading spaces before each row for proper alignment.
  4. Use an inner loop to print uppercase alphabets by converting j + 64 into characters.
  5. Repeat the same logic with another outer loop from 1 to num to complete the lower half of the alphabet diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up alphabet triangle diamond pattern in C using nested loops. This beginner-friendly C program demonstrates ASCII character conversion, nested loops, spacing logic, and alphabet pattern printing.

πŸ” Keywords

Alphabet Diamond Pattern in C, Alphabet Triangle Pattern C, ASCII Pattern Program, Nested Loops in C, C Pattern Printing, C Programming Examples, Character Pattern Program, C Alphabet Pattern.

🏷 Hashtags

#CProgramming #PatternPrograms #AlphabetPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Repeated Number Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",i);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",i);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 5 5 5 5 5
  4 4 4 4
   3 3 3
    2 2
     1
     1
    2 2
   3 3 3
  4 4 4 4
 5 5 5 5 5
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up repeated number triangle diamond pattern using nested for loops. The first outer loop prints the upper inverted triangle by decreasing the number of columns in each row. The second outer loop prints the lower triangle by increasing the number of columns. Instead of printing sequential numbers, the program prints the current row value (i) repeatedly across each row, producing a symmetric repeated number diamond pattern.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the upper inverted triangle.
  3. Print leading spaces before each row for proper alignment.
  4. Use an inner loop to print the current row value (i) repeatedly.
  5. Repeat the same logic with an outer loop from 1 to num to print the lower half of the diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up repeated number triangle diamond pattern in C using nested loops. This beginner-friendly C program demonstrates loop control, spacing logic, repeated number printing, and pattern generation techniques.

πŸ” Keywords

Repeated Number Diamond Pattern in C, Number Triangle Pattern C, Pattern Printing in C, Nested Loops in C, C Programming Examples, Diamond Pattern Program, Repeated Number Pattern, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #NumberPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Number Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 1 2 3 4 5
  1 2 3 4
   1 2 3
    1 2
     1
     1
    1 2
   1 2 3
  1 2 3 4
 1 2 3 4 5
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up number triangle diamond pattern using nested for loops. The first set of loops generates the inverted number triangle by decreasing the number of columns in each row, while the second set generates the normal number triangle by increasing the number of columns. The inner loop prints numbers sequentially from 1 up to the current row length, creating a symmetrical number diamond pattern.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use an outer loop from num down to 1 to print the inverted number triangle.
  3. Print leading spaces using a nested loop for proper alignment.
  4. Print numbers from 1 to the current row value using another nested loop.
  5. Repeat the same logic with an outer loop from 1 to num to print the lower half of the diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up number triangle diamond pattern in C using nested loops. This program demonstrates loop control, number printing, spacing techniques, and pattern generation for beginners.

πŸ” Keywords

C Number Diamond Pattern, Number Triangle Pattern in C, Nested Loops in C, Pattern Printing in C, Diamond Pattern Program, C Programming Examples, Number Pattern Using For Loop, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #NumberPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Binary Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j%2);
                }
                printf("\n");
        }
        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",j%2);
                }
                printf("\n");
        }
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
  1 0 1 0 1 
   1 0 1 0 
    1 0 1 
     1 0 
      1 
      1 
     1 0 
    1 0 1 
   1 0 1 0 
  1 0 1 0 1 
  

πŸ“˜ Explanation

This program combines two major phases to construct a complex binary diamond pattern using nested loops. Unlike focusing on row structures, the inner logic evaluates the expression j%2 to continuously alternate values horizontally.

The first main set of nested loops prints an inverted triangle structure where the rows decrease in size. The second set of nested loops handles the right-side-up triangle layout where rows progressively scale up. Both sections dynamically handle trailing column changes through space formatting.

🧠 Algorithm

  1. Accept the input tracking value 'num' directly from the console interface.
  2. Initialize the top half loop cycling backwards down to 1 to format the inverted section.
  3. Distribute the leading offsets using inner loop restrictions tracking variables 'num' and 'i'.
  4. Run an independent inner sequence printing j%2 to switch values from 1 to 0 sequentially.
  5. Duplicate structural properties in the lower phase loop while flipping the outer loop control direction to iterate forward up to 'num'.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Master nested loop structures in C programming by building a complex geometric inverted and standard binary diamond pattern utilizing alternating columns.

πŸ” Keywords

C program binary diamond pattern, alternating binary column pattern, nested loops pyramid code in C, inverted binary pattern printing, C pattern optimization tricks, complex loop structures in C language.

🏷 Hashtags

#CProgramming #PatternPrograms #BinaryDiamond #Coding #Programming #LearnC #NestedLoops #CLanguage #1printf

⭐ C Program to Print Inverted and Right-Side Up Continuous Number Triangle Diamond Pattern

πŸ“„ Source Code:
#include<stdio.h>

int main()
{
        int num,k=0;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",k++);
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("%d ",k++);
                }
                printf("\n");
        }

        return 0;
}
  
πŸ’» Expected Output (Input: 5):
Enter the number:
5
 0 1 2 3 4
  5 6 7 8
   9 10 11
    12 13
     14
     15
    16 17
   18 19 20
  21 22 23 24
 25 26 27 28 29
  

πŸ“˜ Explanation

This C program prints an inverted and right-side-up continuous number triangle diamond pattern using nested for loops. A global counter variable k is initialized to 0 and is incremented every time a number is printed. Unlike other number patterns that restart counting on every row, this program continues printing numbers sequentially throughout the entire diamond. The first outer loop prints the upper inverted triangle, while the second outer loop prints the lower triangle, creating a complete continuous number diamond pattern.

🧠 Algorithm

  1. Read the input value num from the user.
  2. Initialize a counter variable k = 0.
  3. Use an outer loop from num down to 1 to print the upper inverted triangle.
  4. Print leading spaces for alignment and use an inner loop to print k while incrementing it after every output.
  5. Repeat the same process with another outer loop from 1 to num to print the lower half of the continuous number diamond.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted and right-side-up continuous number triangle diamond pattern in C using nested loops. This beginner-friendly C program demonstrates sequential number printing, nested loops, spacing logic, counter variables, and pattern generation techniques.

πŸ” Keywords

Continuous Number Diamond Pattern in C, Sequential Number Pattern in C, Number Diamond Pattern, Nested Loops in C, Counter Variable Pattern, Pattern Printing in C, C Programming Examples, C Pattern Programs.

🏷 Hashtags

#CProgramming #PatternPrograms #NumberPattern #DiamondPattern #Programming #LearnC #NestedLoops #CLanguage #1printf


⭐ C Program to Print Inverted and Right-Side Up Star Triangle Diamond Pattern

πŸ“Œ ProgramInverted and Right-Side Up Star Triangle Diamond Pattern
πŸ’» LanguageC Programming
πŸ“‚ CategoryPattern Printing
🎯 DifficultyBeginner
⏱ Time ComplexityO(n²)
πŸ’Ύ Space ComplexityO(1)

πŸ“– Introduction

This C program prints an Inverted and Right-Side Up Star Triangle Diamond Pattern using nested for loops. The first half displays an inverted star triangle by decreasing the number of stars in every row, while the second half prints an upright triangle by increasing the number of stars. This program is an excellent exercise for learning nested loops, spacing logic, and pattern printing techniques commonly asked in programming interviews and college practical exams.

πŸ“‘ Table of Contents

  1. Introduction
  2. Algorithm
  3. C Program
  4. Sample Output
  5. Explanation
  6. Dry Run
  7. Flow of Execution
  8. Time Complexity
  9. Space Complexity
  10. Applications
  11. Key Points
  12. Interview Questions
  13. FAQs
  14. Keywords
  15. Conclusion

🧠 Algorithm

  1. Read the input value num from the user.
  2. Use the first outer loop from num down to 1 to print the inverted star triangle.
  3. Print leading spaces before each row.
  4. Print stars using the inner loop.
  5. Use another outer loop from 1 to num to print the upright star triangle.
  6. Display the complete diamond-shaped star pattern.
πŸ’» C Program:
#include<stdio.h>

int main()
{
        int num;
        printf("Enter the number:\n");
        scanf("%d",&num);

        for(int i=num;i>=1;i--)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("* ");
                }
                printf("\n");
        }

        for(int i=1;i<=num;i++)
        {
                for(int k=num;k>=i;k--)
                {
                        printf(" ");
                }
                for(int j=1;j<=i;j++)
                {
                        printf("* ");
                }
                printf("\n");
        }

        return 0;
}
  
πŸ–₯ Sample Output (Input: 5):
Enter the number:
5
 * * * * *
  * * * *
   * * *
    * *
     *
     *
    * *
   * * *
  * * * *
 * * * * *
  

πŸ“˜ Explanation

This C program prints an inverted and right-side up star triangle diamond pattern using nested for loops. The first outer loop decreases the number of stars in each row to create the upper inverted triangle. The second outer loop increases the number of stars row by row to form the lower upright triangle. Leading spaces are printed before each row to align the stars correctly, resulting in a perfectly symmetrical diamond-like pattern.

πŸ” Dry Run

Consider the input:

num = 3
    

First Outer Loop (Inverted Triangle)

i = 3
Output:
* * *

i = 2
Output:
 * *

i = 1
Output:
  *
    

Second Outer Loop (Right-Side Up Triangle)

i = 1
Output:
  *

i = 2
Output:
 * *

i = 3
Output:
* * *
    

Combining both halves produces a symmetric inverted and right-side up star triangle diamond pattern.

⚙ Flow of Execution

Start
   │
   ▼
Read value of num
   │
   ▼
First Outer Loop
(num → 1)
   │
   ▼
Print Leading Spaces
   │
   ▼
Print Stars
   │
   ▼
Repeat Until First Loop Ends
   │
   ▼
Second Outer Loop
(1 → num)
   │
   ▼
Print Leading Spaces
   │
   ▼
Print Stars
   │
   ▼
Repeat Until Second Loop Ends
   │
   ▼
Display Complete Diamond Pattern
   │
   ▼
End
    

⏱ Time Complexity

O(n²)

The program uses two outer loops, and each outer loop contains nested loops for printing spaces and stars. The total number of printed characters grows proportionally to the square of the input size, giving an overall time complexity of O(n²).

πŸ’Ύ Space Complexity

O(1)

The program only uses a few integer variables such as num, i, j, and k. No additional arrays or dynamic memory are allocated, so the space complexity remains constant.

Comments

Popular Posts

πŸŒ™