상세 컨텐츠

본문 제목

Program To Print Triangle Pattern In C

카테고리 없음

by timpelrecenuilun 2020. 11. 5. 02:36

본문



  1. Program To Print Triangle Pattern In C
  2. Triangle Pattern In C
  3. Program To Print Triangle Pattern In Computer
  4. Triangle Pattern For Kids

Write a C program to print equilateral triangle star pattern series of n rows. Logic to print pyramid star pattern series in C programming. Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online. This section contains Pyramid Programs in C, C Programs to print Star Series, and Different Pattern Printing Programs in C Language. Pattern printing programs contains Star Pattern, Number Pattern and Character Pattern printing.

C Program to Print the Double Pyramid Pattern

Pooja

Problem Statement : Program to Print the Double Pyramid Pattern

2
4
6
ABCDEFFEDCBA
ABCDDCBA
ABBA

Explain Me ?

As the above coding is very difficult to understand , so I have divided Program in 5 Steps.Easy steps are as follow ,
Step 0 :
Program has 7 lines i.e (0 to 6)


Variables : i is used to trace the Current Line
Variables : j is used for Subscript variable for Different Loops
Variables : k is used to trace the diff array , for each new value of i (new line) k is incremented

Variable : diff[7] is used for Storing the number of blanks
eg.

Here G is Missing so blank = 1;
Step 1 :
2
4
6
ABCDEF
ABCD
AB

Will be Printed
Step 2 : Initialize Blank i.e for first line blank = 0 , for second line it will be 1 and so on

2
4
6
ABCDEF
ABCD
AB

Will be Printed, Blanks are denoted by
Step 3 :

Here symbol variable is initialized , Consider first Line , We are printing Letter ‘F’ after ‘G’ so initialize it .Pattern
for 3rd line
>> blank = 3 , so
>> symbol = ‘F’ – 1 = ‘E’
step 4 :
2
printf('%c ',symbol--);

Here print remaining characters , until we print ‘A’

This article is aimed at giving a C++ implementation for pattern printing.

  • Simple pyramid pattern
  • #include <iostream>
    voidpypart(intn)
    // outer loop to handle number of rows
    for(inti=0; i<n; i++)
    // inner loop to handle number of columns
    for(intj=0; j<=i; j++ )
    // printing stars
    }
    // ending line after each row
    }
    intmain()
    intn = 5;
    return0;

    Output:

  • After 180 degree rotation
  • Program To Print Triangle Pattern In C

    #include <iostream>
    voidpypart2(intn)
    // number of spaces
    // n in this case
    {
    // inner loop to handle number spaces
    for(intj=0; j<k; j++)
    k = k - 2;
    // inner loop to handle number of columns
    for(intj=0; j<=i; j++ )
    // printing stars
    }
    // ending line after each row
    }
    intmain()
    intn = 5;
    return0;
    C program to print natural numbers in right triangle pattern

    Output:

  • Printing Triangle
  • #include <iostream>
    voidtriangle(intn)
    // number of spaces
    // n in this case
    {
    // values changing acc. to requirement
    cout <<' ';
    // decrementing k after each loop
    // values changing acc. to outer loop
    {
    cout << '* ';
    cout << endl;
    }
    // Driver Function
    {
    triangle(n);
    }

    Output:

  • Number Pattern
  • // C++ code to demonstrate printing pattern of numbers
    usingnamespacestd;
    // Function to demonstrate printing pattern
    {
    intnum = 1;
    // outer loop to handle number of rows
    for(inti=0; i<n; i++)
    // values changing acc. to outer loop
    cout << num << ' ';
    // incrementing number at each column
    cout << endl;
    }
    // Driver Function
    {
    numpat(n);
    }

    Output:

  • Numbers without re assigning
  • // C++ code to demonstrate printing pattern of numbers
    usingnamespacestd;
    // Function to demonstrate printing pattern
    {
    intnum = 1;
    // outer loop to handle number of rows
    for(inti=0; i<n; i++)
    // inner loop to handle number of columns
    for(intj=0; j<=i; j++ )
    // printing number
    num = num + 1;
    cout << endl;
    }
    // Driver Function
    {
    numpat(n);
    }

    Output:

  • Character Pattern
  • // C++ code to demonstrate printing pattern of alphabets
    usingnamespacestd;
    // Function to demonstrate printing pattern
    {
    // ASCII value
    // n in this case
    {
    // values changing acc. to outer loop
    {
    charch = char(num);
    // printing char value
    }
    // incrementing number
    cout << endl;
    }
    // Driver Function
    {
    alphapat(n);
    }

    Output:

  • Continuous Character pattern
  • // C++ code to demonstrate printing pattern of alphabets
    usingnamespacestd;
    // Function to demonstrate printing pattern
    {
    // ASCII value
    // n in this case
    {
    // values changing acc. to outer loop
    {
    charch = char(num);
    // printing char value
    num = num + 1;
    cout << endl;
    }
    // Driver Function
    {
    contalpha(n);
    }

    Output:

    Printing patterns in python language are discussed in the article below :

    This article is contributed by Manjeet Singh(S.Nandini). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Program To Print Triangle Pattern In C

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

    Triangle Pattern In C


    Program To Print Triangle Pattern In Computer

    Recommended Posts:

    Triangle Pattern For Kids