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

Half Diamond Alphabet Series Pattern Program in C

This C program prints a Half Diamond Alphabet Series Pattern using nested for loops. In each row, the alphabets start from A and continue sequentially up to the current column. The pattern is then printed in reverse order to form a half diamond shape.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num, k = 0;

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

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

    // Lower Half
    for(int i = num; i >= 1; i--)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%c ", j + 64);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The first nested for loop prints the upper half of the pattern.
  • The expression j + 64 converts the column number into its corresponding uppercase ASCII character:
    • 1 + 64 = 65 → A
    • 2 + 64 = 66 → B
    • 3 + 64 = 67 → C
    • 4 + 64 = 68 → D
  • Each row starts with A and continues alphabetically up to the current column number.
  • The second nested for loop prints the same pattern in reverse order, forming a Half Diamond Alphabet Series Pattern.

πŸ’» Sample Output

Enter the number: 4 A A B A B C A B C D A B C D A B C A B A

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops and ASCII values can be used to generate a Half Diamond Alphabet Series Pattern. It is an excellent example for beginners to understand character manipulation, nested loops, and alphabet pattern printing in C.

πŸ” Keywords

Half Diamond Alphabet Series Pattern in C, Alphabet Pattern Program in C, ABC Pattern in C, Character Pattern Using ASCII, ASCII Alphabet Pattern, Half Diamond Character Pattern, Nested Loops in C, Pattern Printing Programs in C, C Programming Alphabet Patterns, Alphabet Series Pattern Using For Loop

Half Diamond Alphabet Pattern Program in C

This C program prints a Half Diamond Alphabet Pattern using nested for loops. Each row prints the corresponding uppercase alphabet repeatedly. The expression i + 64 converts the row number into its equivalent ASCII uppercase letter, and the pattern is then printed in reverse order to form a half diamond.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num, k = 0;

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

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

    // Lower Half
    for(int i = num; i >= 1; i--)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%c ", i + 64);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The first nested for loop prints the upper half of the pattern.
  • The expression i + 64 converts the row number into its corresponding uppercase ASCII character:
    • 1 + 64 = 65 → A
    • 2 + 64 = 66 → B
    • 3 + 64 = 67 → C
    • 4 + 64 = 68 → D
  • Each row prints the same alphabet character repeatedly according to the row number.
  • The second nested for loop prints the same pattern in reverse order, creating a Half Diamond Alphabet Pattern.

πŸ’» Sample Output

Enter the number: 4 A B B C C C D D D D D D D D C C C B B A

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops and ASCII values can be used to generate a Half Diamond Alphabet Pattern in C. It is an excellent practice program for learning nested loops, character manipulation, and pattern printing using uppercase alphabets.

πŸ” Keywords

Half Diamond Alphabet Pattern in C, Alphabet Pattern Program in C, Character Pattern in C, ASCII Pattern Program, Uppercase Letter Pattern in C, Half Diamond Character Pattern, Nested Loops in C, Pattern Printing Programs in C, ASCII Value Program in C, C Programming Alphabet Patterns

Half Diamond Continuous Number Pattern Program in C

This C program prints a Half Diamond Continuous Number Pattern using nested for loops. A variable k is initialized to 0 and is incremented after every print operation, resulting in a continuous sequence of numbers throughout both the upper and lower halves of the pattern.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num, k = 0;

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

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

    // Lower Half
    for(int i = num; i >= 1; i--)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", k++);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The variable k is initialized to 0.
  • The first nested for loop prints the upper half of the pattern.
  • Each time printf("%d ", k++) executes, the current value of k is printed, and then k is increased by 1.
  • The second nested for loop prints the lower half while continuing the sequence without resetting k.
  • As a result, the pattern displays continuous numbers in the shape of a half diamond.

πŸ’» Sample Output

Enter the number: 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops and a continuously incrementing variable can be used to generate a Half Diamond Continuous Number Pattern. It is an excellent example for beginners to understand nested loops, post-increment operators, and sequential number pattern generation in C.

πŸ” Keywords

Half Diamond Continuous Number Pattern in C, Continuous Number Pattern in C, Number Pattern Program in C, Sequential Number Pattern, Half Diamond Pattern Using Numbers, Nested Loops in C, Pattern Printing Programs in C, C Programming Examples, Increment Operator in C, Number Pattern Using For Loop

Half Diamond Row Binary Pattern Program in C

This C program prints a Half Diamond Row Binary Pattern using nested for loops. Instead of alternating values in every column, the program prints the same binary digit throughout each row based on the expression i % 2. Odd-numbered rows print 1, while even-numbered rows print 0. The pattern is then repeated in reverse order to form a half diamond.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num;

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

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

    // Lower Half
    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%d ",i%2);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program reads the number of rows from the user.
  • The first nested for loop prints the upper half of the pattern.
  • The expression i % 2 determines the value printed in each row:
    • Odd rows print 1.
    • Even rows print 0.
  • Every element in the same row has the same value because the row number i remains constant.
  • The second nested for loop prints the same pattern in reverse order, creating a Half Diamond Row Binary Pattern.

πŸ’» Sample Output

Enter the number: 4 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 1

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how the modulo operator (%) and nested for loops can be used to generate a Half Diamond Row Binary Pattern. It helps beginners understand row-based pattern generation, nested loops, and the use of the modulo operator in C programming.

πŸ” Keywords

Half Diamond Row Binary Pattern in C, Binary Pattern Program in C, Row Wise Binary Pattern in C, 0 and 1 Pattern in C, Half Diamond Pattern Using Binary Numbers, Nested Loops in C, Pattern Printing Programs in C, C Programming Examples, Modulo Operator Pattern in C, Row Based Binary Pattern in C

Half Diamond Binary Pattern Program in C

This C program prints a Half Diamond Binary Pattern using nested for loops. The program prints alternating 1 and 0 values in each row by using the expression j % 2. The upper half prints the pattern in increasing order, while the lower half prints it in decreasing order to form a half diamond.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num;

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

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

    // Lower Half
    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%d ",j%2);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The first nested for loop prints the upper half of the binary pattern.
  • The expression j % 2 prints alternating values:
    • 1 % 2 = 1
    • 2 % 2 = 0
    • 3 % 2 = 1
    • 4 % 2 = 0
  • The second nested for loop prints the same binary pattern in reverse order.
  • Combining both parts creates a Half Diamond Binary Pattern.

πŸ’» Sample Output

Enter the number: 4 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 1 0 1

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops and the modulo operator (%) can be used to generate a Half Diamond Binary Pattern. It is a useful practice program for beginners to understand nested loops, alternating sequences, and pattern printing in C.

πŸ” Keywords

Half Diamond Binary Pattern in C, Binary Pattern Program in C, 0 and 1 Pattern in C, Half Diamond Pattern Using Binary Numbers, Nested Loops in C, Pattern Printing in C, C Programming Pattern Examples, Modulo Operator Pattern in C, Alternating Binary Pattern in C

Half Diamond Number Pattern Program in C

This C program prints a Half Diamond Number Pattern using nested for loops. The upper half prints the row number repeatedly in each row, while the lower half prints the same pattern in reverse order to create a half diamond shape.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num;

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

    // Upper Half
    for(int i=1;i<=num;i++)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%d ",i);
        }
        printf("\n");
    }

    // Lower Half
    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%d ",i);
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The first nested for loop prints the upper half of the pattern by repeating the current row number in each row.
  • The second nested for loop prints the lower half by decreasing the row number from num to 1.
  • Together, both loops create a Half Diamond Number Pattern.

πŸ’» Sample Output

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

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops can be used to print a Half Diamond Number Pattern by repeating the current row number. It is an excellent practice program for beginners to understand nested loops and pattern printing techniques in C.

πŸ” Keywords

Half Diamond Number Pattern in C, Number Pattern Program in C, Half Diamond Pattern Using Numbers, Nested Loops in C, Pattern Printing Programs in C, C Number Patterns, Beginner C Programming Examples, Number Pattern Using For Loop

Half Diamond Star Pattern Program in C

This C program prints a Half Diamond Star Pattern using nested for loops. It first prints the stars in increasing order and then prints them in decreasing order to create a half diamond shape.

✅ C Program Code


#include<stdio.h>

int main()
{
    int num;

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

    // Upper Half
    for(int i=1;i<=num;i++)
    {
        for(int j=1;j<=i;j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    // Lower Half
    for(int i=num;i>=1;i--)
    {
        for(int j=1;j<=i;j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    return 0;
}

πŸ’‘ Explanation

  • The program accepts the number of rows from the user.
  • The first nested for loop prints the upper half of the pattern by increasing the number of stars in each row.
  • The second nested for loop prints the lower half by decreasing the number of stars in each row.
  • Together, both loops form a Half Diamond Star Pattern.

πŸ’» Sample Output

Enter the number: 4 * * * * * * * * * * * * * * * * * * * *

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“Œ Conclusion

This program demonstrates how nested for loops can be used to print a Half Diamond Star Pattern. It is a beginner-friendly example for understanding nested loops, pattern printing, and loop control in C.

πŸ” Keywords

Half Diamond Star Pattern in C, Star Pattern Program in C, Half Pyramid Pattern in C, Nested Loops in C, Pattern Printing Programs, C Programming Examples, Beginner C Programs, Star Pattern Using For Loop

Full Diamond Number Pattern in C

Full Diamond Number Pattern in C

This C program prints a full diamond-like number pattern using nested for loops. It starts by printing numbers in increasing order and then prints them in decreasing order to form a symmetric structure.

✅ C Program Code:


#include <stdio.h>

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

    // Top half
    for (int i = 1; i <= num; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }

    // Bottom half
    for (int i = num; i >= 1; i--)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}
  

πŸ’‘ Explanation:

  • The first for loop builds the upper part of the diamond using increasing rows.
  • The second for loop mirrors the top by printing decreasing rows.
  • Each row prints numbers from 1 up to the current row index.

πŸ’» Sample Output:

Enter the number:
3
1
1 2
1 2 3
1 2 3
1 2
1

πŸ” Keywords:

Diamond number pattern in C, number pyramid in C, full pyramid C pattern, nested loops example in C, beginner pattern programs, mirror pyramid C

Comments

Popular Posts

πŸŒ™