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++) { ...

Diamond pattern in C:Star, Number, Alphabet & Binary Patterns with Output

⭐ C Program to Print Number Diamond Pattern Using Row Number

πŸ“„ 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");
    }

    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
     1
    2 2
   3 3 3
  4 4 4 4
 5 5 5 5 5
 5 5 5 5 5
  4 4 4 4
   3 3 3
    2 2
     1
  

πŸ“˜ Explanation

This program prints a number diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints the current row number repeatedly using i. As the row number increases, the same number is printed multiple times, creating a symmetric diamond-shaped number pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the number diamond.
  3. Print leading spaces for proper alignment.
  4. Print the current row number repeatedly in each row.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete number diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print a number diamond pattern in C using nested loops. This C program prints the current row number repeatedly to create a diamond-shaped number pattern, making it ideal for beginners learning C pattern programs.

πŸ” Keywords

number diamond pattern in C, number pattern using row number, C pattern program, repeated number pattern, nested loop pattern in C, diamond pattern using numbers, C programming examples, pattern printing in C.

🏷 Hashtags

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

```

⭐ C Program to Print Number Diamond Pattern Using Nested Loops

πŸ“„ 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);
        }

        printf("\n");
    }

    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
    1 2
   1 2 3
  1 2 3 4
 1 2 3 4 5
 1 2 3 4 5
  1 2 3 4
   1 2 3
    1 2
     1
  

πŸ“˜ Explanation

This program prints a number diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern correctly, and the second inner loop prints numbers starting from 1 up to the current row number. Together, these loops form a symmetric diamond-shaped number pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the number diamond.
  3. Print leading spaces for alignment.
  4. Print numbers from 1 to the current row.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete number diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print a number diamond pattern in C using nested loops. This beginner-friendly C program demonstrates how to print increasing numbers in a diamond shape using simple loop logic.

πŸ” Keywords

number diamond pattern in C, C number pattern program, diamond pattern using numbers, nested loop pattern in C, number pattern examples, C programming patterns, pattern printing in C, C programming tutorial.

🏷 Hashtags

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

⭐ C Program to Print Star Diamond Pattern Using Nested Loops

πŸ“„ 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");
    }

    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 a star diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern correctly, and the second inner loop prints stars (*) in each row. Together, these loops create a complete diamond-shaped star pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the star diamond.
  3. Print leading spaces for proper alignment.
  4. Print stars using the second inner loop.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete star diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print a star diamond pattern in C using nested loops. This beginner-friendly C program demonstrates how to combine loops and spaces to create a diamond-shaped pattern using asterisks (*).

πŸ” Keywords

star diamond pattern in C, diamond pattern using stars, C star pattern program, nested loop pattern in C, star pattern using loops, C pattern printing examples, diamond shape pattern, C programming tutorial.

🏷 Hashtags

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

⭐ C Program to Print Alphabet Diamond Pattern Using Row Number

πŸ“„ 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");
    }

    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
     A
    B B
   C C C
  D D D D
 E E E E E
 E E E E E
  D D D D
   C C C
    B B
     A
  

πŸ“˜ Explanation

This program prints an alphabet diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints the same alphabet repeatedly in each row using the expression i + 64. Since the ASCII value of A is 65, each row displays its corresponding alphabet multiple times.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the alphabet diamond.
  3. Print leading spaces to align the pattern.
  4. Print the same alphabet repeatedly in each row using i + 64.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete alphabet diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an alphabet diamond pattern in C using nested loops. This C program uses the row number and ASCII values to print the same uppercase letter repeatedly in each row, making it an excellent example for beginners learning pattern programs.

πŸ” Keywords

alphabet diamond pattern in C, alphabet pattern using row number, ASCII character pattern, C pattern programs, diamond pattern using alphabets, nested loop pattern in C, C programming examples, pattern printing in C.

🏷 Hashtags

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

⭐ C Program to Print Alphabet Diamond Pattern Using Nested Loops

πŸ“„ 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");
    }

    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
    A B
   A B C
  A B C D
 A B C D E
 A B C D E
  A B C D
   A B C
    A B
     A
  

πŸ“˜ Explanation

This program prints an alphabet diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints uppercase alphabets starting from A using the expression j + 64, where the ASCII value of A is 65.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the alphabet diamond.
  3. Print leading spaces for proper alignment.
  4. Print alphabets from A onward using j + 64.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete alphabet diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print an alphabet diamond pattern in C using nested loops. This beginner-friendly C program demonstrates pattern printing with uppercase letters using ASCII values.

πŸ” Keywords

alphabet diamond pattern in C, C alphabet pattern, character pattern program, ASCII pattern in C, diamond pattern using alphabets, nested loop pattern, C programming examples, pattern printing in C.

🏷 Hashtags

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

⭐ C Program to Print Binary Diamond Pattern Using Row Number

πŸ“„ 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");
    }

    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
    0 0
   1 1 1
  0 0 0 0
 1 1 1 1 1
 1 1 1 1 1
  0 0 0 0
   1 1 1
    0 0
     1
  

πŸ“˜ Explanation

This program prints a binary diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints either 0 or 1 based on the current row number using the expression i%2. Odd-numbered rows print 1s, while even-numbered rows print 0s, forming a binary diamond pattern.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the binary diamond.
  3. Print leading spaces for alignment.
  4. Print the value of i%2 repeatedly in each row.
  5. Print the lower half of the diamond using another outer loop.
  6. Repeat until the complete binary diamond pattern is displayed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print a binary diamond pattern in C using nested loops. This program uses the row number and the modulus operator to print alternating rows of 1s and 0s, making it ideal for beginners learning C pattern programs.

πŸ” Keywords

C binary diamond pattern, binary diamond using row number, binary pattern in C, pattern printing in C, nested loop pattern program, C pattern examples, modulus operator in C, C programming tutorial.

🏷 Hashtags

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

⭐ C Program to Print Binary Diamond Pattern Using Nested Loops

πŸ“„ 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");
    }

    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
    1 0
   1 0 1
  1 0 1 0
 1 0 1 0 1
 1 0 1 0 1
  1 0 1 0
   1 0 1
    1 0
     1
  

πŸ“˜ Explanation

This program prints a binary diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints alternating binary values using j%2. Since the values depend on the column number, every row begins with 1 and alternates between 1 and 0.

🧠 Algorithm

  1. Read the number from the user.
  2. Print the upper half of the binary pattern.
  3. Print leading spaces using the first inner loop.
  4. Print alternating binary values using j%2.
  5. Print the lower half using another outer loop.
  6. Repeat until the complete binary diamond pattern is printed.

⏱ Time Complexity

O(n²)

πŸ’Ύ Space Complexity

O(1)

πŸ“ Search Description

Learn how to print a binary diamond pattern in C using nested loops. This program prints alternating 1s and 0s to form a diamond shape and is a great example for beginners learning pattern printing in C.

πŸ” Keywords

C binary diamond pattern, binary pattern in C, diamond pattern using loops, C pattern programs, alternating 1 and 0 pattern, nested loop examples, pattern printing in C, C programming examples.

🏷 Hashtags

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

Comments

Popular Posts

πŸŒ™