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, a triangle pattern can be created using loops and the printf() function. There are different types of triangle patterns that can be created, such as a right triangle, an isosceles triangle, or a equilateral triangle. Here is an example of how to create a right-angled triangle pattern of asterisks:

Copy code

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

This code uses nested loops to create a right-angled triangle pattern of 5 lines. The outer loop controls the number of rows and the inner loop controls the number of asterisks in each row. The number of asterisks in each row is equal to the row number, so the first row has 1 asterisk, the second row has 2 asterisks, and so on.

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

Copy code

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

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?