a program in c with detail explanation to print the pattern of a right angled triangle using a for loop.

This C program creates a right triangle pattern where each line displays numbers in increments of 1 up to the line number. Use nested "for" loops to control the number of lines and numbers displayed in each line, creating the desired pattern.


a C program to print the pattern of a right angled triangle using a for loop.

#include <stdio.h> int main() { int i, j, rows; // Declare variables i,j for loop counters and rows for user input. printf("\n Enter a total number of rows :\n "); // show this message to user for input. scanf("%d", &rows); // Read and store the value of rows from the user. for (i=1; i<=rows;i++) { // Starting a loop to generate number of rows. for (j = 1; j <= i; j++) // Nested for loop to print numbers based on the current row. printf("%d",j); // show the value of 'j'. printf("\n"); } return(0); }

Program Explanation
In the above loop, the variable i is initialized to 1 and the loop will continue until i is less than or equal to the value of the "rows" variable. In each iteration of the outer loop, another loop is started with variable j, which starts at 1 and continues until j is less than or equal to the value of i.
On each iteration of the inner loop, the printf() function prints the value of j to the console. This value is printed j times because the value of j is incremented by 1 on each iteration of the inner loop.
After the inner loop completes, the outer loop prints the newline code (\n) to create a new line.
Finally, the outer loop increments the value of i by 1 and this process repeats until i<= rows are invalid.


Previous :-->> 18.Write a program in c to calculate the sum of all prime numbers between two given numbers using a for loop.
 -->> NEXT: 20. Write a program in c to calculate the factorial of a given number using a for loop.
-->>ALL Loops Assignments in c