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 5: Star, Number, Alphabet & Binary Patterns with Output

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

        printf("\n");
    }

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

πŸ“˜ Explanation

This program prints an inverted star triangle pattern using nested loops. The outer loop starts from the entered number and decreases to 1, controlling the number of rows. The first inner loop prints leading spaces to align the pattern, while the second inner loop prints the required number of stars in each row. As the number of stars decreases with each iteration, an inverted star triangle is formed.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print stars equal to the current row value.
  5. Move to the next line after each row.
  6. Repeat until the complete inverted star triangle is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted star triangle pattern in C using nested loops. This beginner-friendly C program demonstrates pattern printing with stars and spaces, making it perfect for beginners learning loops and pattern programs in C.

πŸ” Keywords

inverted star triangle pattern in C, C program for star pattern, inverted triangle pattern in C, star pattern using nested loops, C pattern program, pattern printing in C, nested loops in C, C programming examples.

🏷 Hashtags

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

```

⭐ C Program to Print Inverted Repeated Binary 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%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 repeated binary triangle pattern using nested loops. The outer loop starts from the entered number and decreases to 1, controlling the number of rows. The first inner loop prints leading spaces for proper alignment, while the second inner loop prints either 1 or 0 repeatedly based on the parity of the current row. The expression i % 2 returns 1 for odd rows and 0 for even rows, creating an inverted repeated binary pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print i % 2 repeatedly for each row.
  5. Move to the next line after each row.
  6. Repeat until the complete inverted repeated binary triangle is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted repeated binary triangle pattern in C using nested loops. This beginner-friendly C program uses the modulo operator to print repeated 1s and 0s based on the row number, making it ideal for learning binary pattern printing in C.

πŸ” Keywords

inverted repeated binary triangle pattern in C, C program for repeated binary pattern, binary pattern using modulo operator, repeated binary pattern in C, C pattern program, nested loops in C, pattern printing in C, C programming examples.

🏷 Hashtags

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

```

⭐ C Program to Print Inverted Binary 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%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
  

πŸ“˜ Explanation

This program prints an inverted binary triangle pattern using nested loops. The outer loop controls the number of rows, starting from the entered number and decreasing to 1. The first inner loop prints leading spaces for proper alignment, while the second inner loop prints alternating 1 and 0 values using the expression j % 2. Since the remainder alternates between 1 and 0 for consecutive values of j, the program creates a binary triangle in inverted form.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print alternating 1 and 0 values using j % 2.
  5. Move to the next line after each row.
  6. Repeat until the complete inverted binary triangle is displayed.

⏱ 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 beginner-friendly C program uses the modulo operator to generate alternating 1 and 0 values, making it ideal for learning binary pattern printing in C.

πŸ” Keywords

inverted binary triangle pattern in C, C program for binary pattern, binary pattern in C, modulo operator pattern, C pattern program, nested loops in C, pattern printing in C, C programming examples.

🏷 Hashtags

#CProgramming #PatternPrograms #BinaryPattern #InvertedTriangle #Coding #Programming #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=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 repeated alphabet triangle pattern using nested loops. The outer loop starts from the entered number and decreases to 1, controlling the number of rows. The first inner loop prints leading spaces to align the pattern, while the second inner loop prints the same uppercase alphabet repeatedly in each row. The expression i + 64 converts the current row number into its corresponding uppercase ASCII character, producing a repeated alphabet triangle in inverted form.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print the corresponding uppercase alphabet repeatedly using its ASCII value.
  5. Move to the next line after each row.
  6. Repeat until the complete inverted repeated alphabet triangle is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted repeated alphabet triangle pattern in C using nested loops. This beginner-friendly C program uses ASCII values to print the same uppercase alphabet repeatedly in each row, making it ideal for learning alphabet pattern printing in C.

πŸ” Keywords

inverted repeated alphabet triangle pattern in C, C program for repeated alphabet pattern, alphabet triangle pattern in C, repeated character pattern in C, ASCII character pattern, C pattern program, nested loops in C, pattern printing in C.

🏷 Hashtags

#CProgramming #PatternPrograms #AlphabetPattern #InvertedTriangle #Coding #Programming #NestedLoops #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=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");
    }

    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 prints an inverted alphabet triangle pattern using nested loops. The outer loop controls the number of rows, starting from the entered number and decreasing to 1. The first inner loop prints leading spaces to align the pattern, while the second inner loop prints uppercase alphabets from A up to the current row. The expression j + 64 converts numbers into their corresponding uppercase ASCII characters, producing the alphabet triangle.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print uppercase alphabets from A to the current row using ASCII values.
  5. Move to the next line after each row.
  6. Repeat until the complete inverted alphabet triangle is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted alphabet triangle pattern in C using nested loops. This beginner-friendly C program uses ASCII values to print uppercase letters from A onward, making it ideal for learning alphabet pattern printing in C.

πŸ” Keywords

inverted alphabet triangle pattern in C, C program for alphabet pattern, alphabet triangle pattern in C, ASCII character pattern in C, C pattern program, nested loops in C, pattern printing in C, C programming examples.

🏷 Hashtags

#CProgramming #PatternPrograms #AlphabetPattern #InvertedTriangle #Coding #Programming #NestedLoops #CLanguage #1printf

```

⭐ C Program to Print Inverted 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 repeated number triangle pattern using nested loops. The outer loop starts from the entered number and decreases to 1, controlling the number of rows. The first inner loop prints leading spaces to align the pattern, while the second inner loop prints the current row number repeatedly. As the row number decreases, the pattern forms an inverted triangle of repeated numbers.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print the current row number repeatedly in each row.
  5. Move to the next line after each row.
  6. Repeat until the inverted repeated number triangle is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted repeated number triangle pattern in C using nested loops. This beginner-friendly C program prints the current row number repeatedly while decreasing the number of rows, making it ideal for learning pattern printing in C.

πŸ” Keywords

inverted repeated number triangle pattern in C, C program for repeated number pattern, inverted number pattern in C, C pattern program, nested loops in C, pattern printing in C, C programming examples, repeated number triangle pattern.

🏷 Hashtags

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

```

⭐ C Program to Print Inverted 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 number triangle pattern using nested loops. The outer loop controls the number of rows from the entered value down to 1. The first inner loop prints leading spaces to align the pattern, while the second inner loop prints numbers starting from 1 up to the current row value. As the number of rows decreases, the pattern forms an inverted triangle.

🧠 Algorithm

  1. Read the number from the user.
  2. Start the outer loop from the entered number down to 1.
  3. Print leading spaces for proper alignment.
  4. Print numbers from 1 to the current row value.
  5. Move to the next line after each row.
  6. Repeat until the inverted triangle is complete.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an inverted number triangle pattern in C using nested loops. This beginner-friendly C program prints numbers from 1 to the current row value while decreasing the number of rows, making it perfect for learning pattern printing in C.

πŸ” Keywords

inverted number triangle pattern in C, C program for inverted number pattern, number triangle pattern, C pattern program, nested loops in C, pattern printing in C, C programming examples, inverted pattern using numbers.

🏷 Hashtags

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

```

Comments

Popular Posts

πŸŒ™