Inverted Triangle Pattern In C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

In C, an inverted triangle pattern can be created using loops and the printf() function. It is similar to the right-angled triangle pattern, but the number of asterisks in each row decreases. Here is an example of how to create an inverted right-angled triangle pattern of asterisks:

Copy code

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

This code uses nested loops to create an inverted right-angled triangle pattern of 5 lines. The outer loop controls the number of rows, starting at 5 and decreasing by 1 in each iteration. The inner loop controls the number of asterisks in each row, which is equal to the current value of the outer loop variable.

You can change the number of rows of the triangle by changing the initial value and the condition of the outer loop variable. For example, to create a triangle of 8 lines you can change the initial value of the outer loop variable to 8, like this:

Copy code

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

As you can see, the code for the inverted triangle is similar to the right-angled triangle, but the initial value and the condition of the outer loop is changed to have the inverted triangle pattern.

You can also use different characters or symbols to create different patterns.

7. Loops

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?