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...

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

πŸ”€ C Program to Print Repeated Alphabet Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%c ",i+64);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```

πŸ”€ C Program to Print Alphabet Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%c ",j+64);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```

πŸ”’ C Program to Print Repeated Binary Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%d ",i%2);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```

πŸ”’ C Program to Print Binary Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%d ",j%2);
        }

        printf("\n");
    }

    for(int i=1;i<=num;i++)
    {
        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
  
```

πŸ”’ C Program to Print Repeated Number Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%d ",i);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```

πŸ”’ C Program to Print Increasing and Decreasing Number 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 j=1;j<=i;j++)
        {
            printf("%d ",j);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```html

πŸ”’ C Program to Print Continuous Number Increasing and Decreasing 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 j=1;j<=i;j++)
        {
            printf("%d ",k++);
        }

        printf("\n");
    }

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

        printf("\n");
    }
}
  
πŸ’» 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
  
```

Comments

Popular Posts

πŸŒ™