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

πŸ”’ C Program to Print Continuous Number Triangle Pattern

#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 j=i;j<=num;j++)
        {
            printf("%d ",k++);
        }

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

0 1 2 3 4
5 6 7 8
9 10 11
12 13
14
  

πŸ”’ C Program to Print Repeated Binary Triangle Pattern

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
  

πŸ”’ C Program to Print Binary Number Triangle Pattern

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
  

⭐ C Program to Print Inverted Star Pattern

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

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

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

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

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

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

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

πŸ”€ C Program to Print Alphabet Triangle Pattern

#include <stdio.h>

int main()
{
    int num;

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

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

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

πŸ”’ C Program to Print Repeated Number Triangle Pattern

#include <stdio.h>

int main()
{
    int num;

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

    for(int i=1;i<=num;i++)
    {
        for(int j=i;j<=num;j++)
        {
            printf("%d ",i);
        }

        printf("\n");
    }

    return 0;
}
  

πŸ’‘ Sample Output (Input: 5)

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

πŸ”’ C Program to Print Descending Number Pattern

#include <stdio.h>

int main()
{
    int num;

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

    for(int i=1;i<=num;i++)
    {
        for(int j=i;j<=num;j++)
        {
            printf("%d ",j);
        }

        printf("\n");
    }

    return 0;
}
  

πŸ“ Explanation:

This C program prints a descending number pattern using nested loops. The outer loop controls the rows, while the inner loop prints numbers starting from the current row number up to the entered number.

πŸ’‘ Sample Output (Input: 5)

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

Comments

Popular Posts

πŸŒ™