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

```html id="continuousNumberTrianglePattern"

πŸ”’ C Program to Print 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 = 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;
}
  
⚠️ Note: In this program, the variable k is declared twice (once globally and once inside the loop). The outer k is used for printing numbers, while the inner k is used for spacing.
πŸ’» 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 a continuous number triangle pattern using nested loops. The first inner loop prints spaces for alignment. The variable k starts from 0 and increments after every number is printed, resulting in a sequence of continuous numbers throughout the triangle.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and numbers.

πŸ”‘ Keywords

Continuous Number Triangle Pattern in C, Floyd's Triangle in C, Number Pattern Program, Nested Loop Programs, C Programming Patterns, Triangle Pattern Using Numbers, Incrementing Number Pattern

🏷 Hashtags

#CProgramming #PatternProgram #NumberPattern #FloydsTriangle #Coding #LearnC #1printf

``` ```html id="repeatedNumberTrianglePattern"

πŸ”’ C Program to Print 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 = 1; k <= i; k++)
        {
            printf(" ");
        }

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

        printf("\n");
    }

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

     5
    4 4
   3 3 3
  2 2 2 2
 1 1 1 1 1
  

πŸ“ Explanation

This program prints a repeated number triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints the current row number repeatedly. As the value of i decreases, the triangle grows wider and displays the same number multiple times in each row.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and numbers.

πŸ”‘ Keywords

Repeated Number Triangle Pattern in C, Number Pattern Program, Triangle Pattern Using Numbers, Nested Loop Programs in C, C Programming Pattern Examples, Number Pyramid Pattern

🏷 Hashtags

#CProgramming #PatternProgram #NumberPattern #TrianglePattern #Coding #LearnC #1printf

``` ```html id="numberTrianglePattern"

πŸ”’ C Program to Print Increasing 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 = 1; k <= i; k++)
        {
            printf(" ");
        }

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

        printf("\n");
    }

    return 0;
}
  
πŸ’» Expected Output (Input: 5):


Enter the number:
5
     5 
    5 4 
   5 4 3 
  5 4 3 2 
 5 4 3 2 1 

  

πŸ“ Explanation

This program prints an increasing number triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints numbers starting from the current row value up to the entered number. As the rows increase, more numbers are displayed, forming a triangle pattern.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and numbers.

πŸ”‘ Keywords

Number Triangle Pattern in C, Increasing Number Pattern, Nested Loop Programs in C, Number Pyramid Pattern, C Programming Pattern Examples, Triangle Pattern Using Numbers

🏷 Hashtags

#CProgramming #PatternProgram #NumberPattern #TrianglePattern #Coding #LearnC #1printf

``` ```html id="sameAlphabetTrianglePattern"

πŸ”€ C Program to Print 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 = 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

     A
    B B
   C C C
  D D D D
 E E E E E
  

πŸ“ Explanation

This program prints a repeated alphabet triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while 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 (1=A, 2=B, 3=C, and so on).

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and alphabet characters.

πŸ”‘ Keywords

Repeated Alphabet Triangle Pattern in C, Character Pattern Program in C, ASCII Alphabet Pattern, Letter Triangle Pattern, Nested Loop Programs in C, C Programming Pattern Examples

🏷 Hashtags

#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf

``` ```html id="alphabetIncreasingTrianglePattern"

πŸ”€ C Program to Print 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 = 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
    A B
   A B C
  A B C D
 A B C D E
  

πŸ“ Explanation

This program prints an alphabet triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints alphabets in ascending order. The expression j + 64 converts numbers into uppercase letters using ASCII values, where 1=A, 2=B, 3=C, and so on.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and alphabet characters.

πŸ”‘ Keywords

Alphabet Triangle Pattern in C, Character Pattern Program, ASCII Alphabet Pattern, C Programming Pattern Examples, Letter Triangle Pattern, Nested Loop Programs in C, Alphabet Pyramid Pattern

🏷 Hashtags

#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf

``` ```html id="starTrianglePattern"

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

        printf("\n");
    }

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

     *
    * *
   * * *
  * * * *
 * * * * *
  

πŸ“ Explanation

This program prints a right-angled star triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while the second inner loop prints stars (*) according to the current row number. Each row contains one more star than the previous row.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and stars.

πŸ”‘ Keywords

Star Triangle Pattern in C, Pyramid Pattern in C, Star Pattern Program, Nested Loop Pattern Programs, Triangle Pattern Using Stars, C Programming Pattern Examples

🏷 Hashtags

#CProgramming #PatternProgram #StarPattern #PyramidPattern #Coding #LearnC #1printf

``` ```html id="sameAlphabetTrianglePattern"

πŸ”€ C Program to Print 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 = 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 
    B B 
   C C C 
  D D D D 
 E E E E E 

  

πŸ“ Explanation

This program prints a repeated alphabet triangle pattern using nested loops. The first inner loop prints spaces for proper alignment, while the second inner loop prints the same alphabet repeatedly in each row. The expression i + 64 converts the row number into its corresponding uppercase alphabet using ASCII values (1=A, 2=B, 3=C, etc.).

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and characters.

πŸ”‘ Keywords

Repeated Alphabet Triangle Pattern in C, Character Pattern Program in C, ASCII Character Pattern, Alphabet Triangle Using Nested Loops, C Pattern Programs, Letter Pattern in C Programming

🏷 Hashtags

#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf

``` ```html id="alphabetTrianglePattern"

πŸ”€ C Program to Print 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 = 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 
    E D 
   E D C 
  E D C B 
 E D C B A 

  

πŸ“ Explanation

This program prints an alphabet triangle pattern using nested loops. The first inner loop prints spaces to align the pattern. The second inner loop prints characters by converting numbers to uppercase letters using j + 64, where 1 = A, 2 = B, 3 = C, and so on.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and alphabet characters.

πŸ”‘ Keywords

Alphabet Triangle Pattern in C, Character Pattern Program in C, C Alphabet Patterns, Nested Loop Pattern Programs, ASCII Character Pattern, Triangle Pattern Using Alphabets

🏷 Hashtags

#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf

``` ```html id="a7n5xq"

πŸ”’ C Program to Print Alternate 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 ", 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 prints an alternate binary triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while the second inner loop prints either 1 or 0 based on the current row number using i % 2. Odd rows print 1s and even rows print 0s.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and binary values.

πŸ”‘ Keywords

Alternate Binary Triangle Pattern in C, Binary Pattern Program in C, 0 and 1 Triangle Pattern, C Pattern Programs, Nested Loop Programs, Odd Even Row Pattern in C

🏷 Hashtags

#CProgramming #PatternProgram #BinaryPattern #NumberPattern #Coding #LearnC #1printf

``` ```html

πŸ”’ C Program to Print Binary 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++)
    {
        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 binary triangle pattern using nested loops. The first inner loop prints spaces for proper alignment, while the second inner loop prints alternating 1s and 0s using the expression j % 2. When j is odd, 1 is printed; when j is even, 0 is printed.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and binary numbers.

πŸ”‘ Keywords

Binary Triangle Pattern in C, 0 and 1 Pattern Program in C, C Pattern Programs, Number Triangle Pattern, Nested Loop Programs in C, Binary Pattern Using Modulus Operator

🏷 Hashtags

#CProgramming #PatternProgram #BinaryPattern #NumberPattern #Coding #LearnC #1printf

``` ```html

πŸ”’ C Program to Print 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++)
    {
        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

     1
    2 2
   3 3 3
  4 4 4 4
 5 5 5 5 5
  

πŸ“ Explanation

This program prints a number triangle pattern. The outer loop controls the rows, the first inner loop prints spaces for alignment, and the second inner loop prints the row number repeatedly according to the current row count.

⏱ Time Complexity

O(n²) because nested loops are used to print spaces and numbers.

πŸ”‘ Keywords

C Number Triangle Pattern, Number Pattern in C, Pyramid Pattern in C, C Programming Pattern Programs, Repeating Number Triangle, C Pattern Examples

🏷 Hashtags

#CProgramming #PatternProgram #NumberPattern #Programming #LearnC #Coding #1printf

```

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

#include <stdio.h>
int main( )
{
    int num;
    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);
        }
        printf("\n");
    }
}
  

πŸ“ Explanation:

This program prints a right-aligned triangle of increasing numbers. Spaces are printed first, followed by numbers from 1 to i on each line.

πŸ’‘ Sample Output (for input 5):

     1 
    1 2 
   1 2 3 
  1 2 3 4 
 1 2 3 4 5 
  

πŸ” Keywords:

C pattern programs, triangle pattern in C, right aligned triangle, beginner C exercises

```html 50+ Triangle Pattern Programs in C with Source Code, Output & Explanation ```

Comments

Popular Posts

πŸŒ™