Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

C Triangle Pattern Programs 1: Star, Number, Alphabet & Binary Patterns with Output

⭐ C Program to Print Inverted Binary Triangle Pattern Using Row Number

πŸ“„ Source Code:
#include

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");
    }

    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
  

πŸ“˜ Explanation

This program prints an inverted binary triangle pattern using nested loops. The first inner loop prints leading spaces to shift the pattern toward the right. The second inner loop prints either 0 or 1 based on the current row number using the expression i%2. Odd-numbered rows print 1s, while even-numbered rows print 0s. The number of values decreases in each row, creating an inverted triangular pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Run the outer loop from 1 to num.
  3. Print leading spaces using the first inner loop.
  4. Print the value of i%2 repeatedly in each row.
  5. Move to the next line after completing a row.
  6. Repeat until the pattern is completed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted binary triangle pattern in C using nested loops. This pattern uses the row number and modulus operator to print alternating rows of 1s and 0s.

πŸ” Keywords

C binary pattern program, inverted binary triangle, binary triangle using row number, 0 and 1 pattern in C, nested loop pattern programs, pattern printing using loops, modulus operator examples, C programming examples.

🏷 Hashtags

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

``` ```html

⭐ C Program to Print Inverted Binary Triangle Pattern

πŸ“„ Source Code:
#include 

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 ",j%2);
        }

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted binary triangle pattern using nested loops. The first inner loop prints leading spaces to shift the pattern toward the right. The second inner loop prints binary values (0 and 1) using the expression j%2. As the row number increases, the number of printed values decreases, forming an inverted triangular pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Run the outer loop from 1 to num.
  3. Print leading spaces using the first inner loop.
  4. Print binary values using j%2 in the second inner loop.
  5. Move to the next line after each row.
  6. Repeat until the pattern is completed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted binary triangle pattern in C using nested loops. This program demonstrates pattern printing with 0s and 1s using the modulus operator and loop concepts.

πŸ” Keywords

C binary pattern program, inverted binary triangle, binary pattern in C, nested loop pattern programs, 0 and 1 pattern printing, C programming examples, modulus operator pattern, pattern printing using loops.

🏷 Hashtags

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

```

⭐ C Program to Print Inverted Right-Aligned Star Triangle 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("* ");
        }

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted right-aligned star triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints stars (*) based on the current row value. As the outer loop decreases from the entered number to 1, the number of stars decreases in each row, forming an inverted triangular shape.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C star pattern program, inverted star triangle, right aligned star pattern, nested loop pattern programs, star triangle in C, pattern printing using loops, C programming examples.

🏷 Hashtags

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

πŸ”’ C Program to Print Inverted Right-Aligned Continuous Number Triangle 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 = i; j >= 1; 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
  

πŸ“˜ Explanation

This program prints an inverted right-aligned continuous number triangle pattern. The variable k starts from 0 and increments after every number is printed. The first inner loop prints leading spaces to align the pattern towards the right. The second inner loop prints continuous numbers, creating an inverted triangular shape.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C continuous number pattern, inverted triangle pattern, right aligned number triangle, continuous number printing in C, nested loop pattern programs, pattern printing in C, C programming examples.

🏷 Hashtags

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

πŸ”’ C Program to Print Inverted Right-Aligned Repeated Descending Number Triangle 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 = i; j >= 1; 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
  

πŸ“˜ Explanation

This program prints an inverted right-aligned repeated descending number triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints the current row number repeatedly. As the outer loop decreases from the entered number to 1, both the value and the number of elements in each row decrease, creating an inverted triangular shape.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C repeated number pattern, descending number triangle, inverted number pattern in C, right aligned triangle pattern, nested loop pattern programs, pattern printing in C, C programming examples.

🏷 Hashtags

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

πŸ”’ C Program to Print Inverted Right-Aligned Descending Number Triangle 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 = i; j >= 1; j--)
        {
            printf("%d ", j);
        }

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted right-aligned descending number triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints numbers in descending order from the current row value down to 1. As the outer loop decreases, both the starting number and the number of elements printed in each row decrease.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C descending number pattern, inverted number triangle pattern, right aligned number pattern, descending triangle in C, nested loop pattern programs, pattern printing in C, C programming examples.

🏷 Hashtags

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

πŸ”€ C Program to Print Inverted Right-Aligned Repeated Alphabet Triangle 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");
    }

    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
  

πŸ“˜ Explanation

This program prints an inverted right-aligned repeated alphabet triangle pattern. The first inner loop prints leading spaces, causing the pattern to shift towards the right on each row. The second inner loop prints the same alphabet repeatedly in each row. The expression i + 64 converts the current row number into its corresponding uppercase alphabet using ASCII values. Since the outer loop decreases from num to 1, both the alphabet and the number of characters decrease in each row.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C alphabet pattern program, repeated alphabet triangle pattern, inverted alphabet pattern, right aligned character pattern, ASCII value pattern in C, nested loop pattern programs, C programming examples.

🏷 Hashtags

#CProgramming #AlphabetPattern #PatternPrograms #Coding #Programming #LearnC #NestedLoops #ASCII #CLanguage #1printf

πŸ”’ C Program to Print Inverted Right-Aligned Alphabet Triangle

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

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

    for(int i = num; i >= 1; i--)
    {
        // Inner loop for printing leading spaces
        for(int k = num; k >= i; k--)
        {
            printf("  ");
        }
        // Inner loop for printing uppercase alphabets via ASCII mapping
        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 
  

πŸ“˜ Explanation

This program displays a right-aligned, inverted character triangle pattern by pairing nested loop logic with character type formatting via ASCII offsets. The outer loop controls rows using a decrementing index i starting from the user's input down to 1. The first inner loop k tracks spacing; as i drops, the expression forces an increasing block of double spaces, padding the structure dynamically to the right. The second inner loop j prints alphabets up to the current row width i. By applying the format specifier %c to the mathematical integer logic j + 64, it maps loop increments directly to uppercase ASCII boundaries where 65 yields 'A', 66 yields 'B', and so on.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C alphabet pattern programs, inverted right aligned character pattern, ASCII alphabet printing in C, nested loops space management, C pattern optimization tricks, interview coding questions C, 1printf patterns tutorial.

🏷 Hashtags

#CProgramming #AlphabetPattern #LogicBuilding #Coding #Programming #LearnC #ASCIIMath #NestedLoops #1printf

πŸ”’ C Program to Print Inverted Right-Aligned Repeated Number Triangle 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");
    }

    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
  

πŸ“˜ Explanation

This program prints an inverted right-aligned repeated number triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints the current row number repeatedly. Since the outer loop decreases from num to 1, both the number and the size of each row decrease gradually.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C repeated number pattern, inverted number triangle pattern, right aligned number triangle, nested loop pattern programs, repeated digit triangle, pattern printing in C, C programming examples.

🏷 Hashtags

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

πŸ”’ C Program to Print Inverted Right-Aligned Number Triangle 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");
    }

    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
  

πŸ“˜ Explanation

This program prints an inverted right-aligned number triangle pattern. The outer loop controls the rows from the entered number down to 1. The first inner loop prints leading spaces, causing the pattern to shift to the right on each row. The second inner loop prints numbers from 1 up to the current row value. As the rows decrease, the triangle gradually becomes smaller.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C number pattern program, inverted right aligned triangle, number triangle pattern in C, nested loop pattern programs, inverted number triangle, pattern printing using loops, C programming examples.

🏷 Hashtags

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

πŸ”€ C Program to Print Inverted Repeated Alphabet Triangle Pattern

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

int main()
{
    int num;

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

    for(int i = 1; i <= num; i++)
    {
        for(int k = 1; k <= i; k++)
        {
            printf("  ");
        }

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

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted repeated alphabet triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints the same alphabet multiple times in each row. The expression i + 64 converts the row number into its corresponding uppercase alphabet using ASCII values. Therefore, row 1 prints A, row 2 prints B, row 3 prints C, and so on.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C alphabet pattern program, repeated alphabet triangle pattern, inverted character pattern in C, ASCII value pattern program, nested loop pattern examples, alphabet triangle using loops, C programming pattern questions.

🏷 Hashtags

#CProgramming #AlphabetPattern #PatternPrograms #Coding #Programming #LearnC #NestedLoops #ASCII #CLanguage #1printf

πŸ”€ C Program to Print Inverted Alphabet Triangle Pattern

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

int main()
{
    int num;

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

    for(int i = 1; i <= num; i++)
    {
        for(int k = 1; k <= i; k++)
        {
            printf("  ");
        }

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

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted alphabet triangle pattern. The first inner loop prints leading spaces to shift the pattern towards the right. The second inner loop prints characters in descending order from the entered value down to the current row. The expression j + 64 converts numbers into uppercase alphabets using ASCII values (1 = A, 2 = B, 3 = C, and so on).

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C alphabet pattern program, inverted alphabet triangle pattern, character pattern in C, ASCII value pattern programs, nested loop pattern programs, alphabet triangle pattern, C programming examples.

🏷 Hashtags

#CProgramming #AlphabetPattern #PatternPrograms #Coding #Programming #LearnC #NestedLoops #ASCII #CLanguage #1printf

πŸ”’ C Program to Print Right-Aligned Binary Row Triangle Pattern

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

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

    for(int i = 1; i <= num; i++)
    {
        // Inner loop for printing leading spaces
        for(int k = num; k >= i; k--)
        {
            printf("  ");
        }
        // Inner loop for printing row-based binary values
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", i % 2);
        }
        printf("\n");
    }

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

πŸ“˜ Explanation

This program combines right-alignment spacing with row-based binary logic to print a mirrored triangle pattern. The outer loop i runs from 1 up to the user-input number, controlling the row processing. The first inner loop k handles right-alignment by generating double spaces, which decrease as i increases. The second inner loop j manages the actual value output. Instead of counting up, it prints the evaluation of i % 2. Because the display relies on the row index i, all elements within a single row match: odd rows print entirely as 1s and even rows print entirely as 0s.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C right aligned binary pattern, mirrored binary row triangle, nested loops spaces and binary C, modulo pattern printing logic, C pattern question answers, 1printf patterns tutorials.

🏷 Hashtags

#CProgramming #PatternPrograms #LogicBuilding #Coding #Programming #LearnC #BinaryPatterns #NestedLoops #1printf

πŸ”’ C Program to Print Right-Aligned Binary Triangle Pattern

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

int main()
{
    int num;

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

    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
        1 0
      1 0 1
    1 0 1 0
  1 0 1 0 1
  

πŸ“˜ Explanation

This program prints a right-aligned binary triangle pattern. The first inner loop prints the required spaces to align the pattern to the right. The second inner loop prints alternating 1s and 0s using the expression j % 2. Since odd numbers give remainder 1 and even numbers give remainder 0, a binary pattern is formed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C binary pattern program, right aligned binary triangle, binary triangle pattern in C, 1 and 0 pattern program, nested loop pattern programs, modulo operator pattern, C programming examples.

🏷 Hashtags

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

πŸ”’ C Program to Print Right-Aligned Number Triangle Pattern

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

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

    for(int i = 1; i <= num; i++)
    {
        // Inner loop for printing leading spaces
        for(int k = num; k >= i; k--)
        {
            printf("  ");
        }
        // Inner loop for printing numbers
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }

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

πŸ“˜ Explanation

This program creates a right-aligned triangle pattern using numbers. It shifts the pattern to the right by using two separate inner loops inside a single outer loop. The outer loop i controls the total number of rows from 1 up to the entered number. The first inner loop k handles the formatting by printing leading double spaces, which decreases in count as we move down the rows. The second inner loop j runs from 1 up to the current row number i, printing incrementing numbers separated by spaces to form the final structure.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ” Keywords

C right aligned pattern, right triangle number pattern in C, space padded pattern loops, nested loop pattern printing, mirrored number triangle C, C programming basic interview questions, pattern tutorials for beginners.

🏷 Hashtags

#CProgramming #PatternPrograms #LogicBuilding #Coding #Programming #LearnC #NestedLoops #SoftwareEngineering #1printf

Comments

Popular Posts

πŸŒ™