Posts

Showing posts from March, 2026

⓲C Program to Print Right Star Triangle

  Program: Right Star Triangle #include <stdio.h> int main () { int i , j ; // Outer loop controls the number of rows for ( i = 1 ; i <= 5 ; i ++ ) { // Inner loop prints stars in each row for ( j = 1 ; j <= i ; j ++ ) { printf ( "* " ); } // Move to next line after each row printf ( "\n" ); } return 0 ; } Output * * * * * * * * * * * * * * * Explanation 1️⃣ Header File #include <stdio.h> This line allows us to use printf() for printing output. 2️⃣ Main Function int main () The program execution starts from the main() function . 3️⃣ Variable Declaration int i , j ; i → controls rows j → controls number of stars in each row 4️⃣ Outer Loop (Rows) for ( i = 1 ; i <= 5 ; i ++ ) This loop decides how many rows will print . i value Row 1 Row 1 2 Row 2 3 Row 3 4 Row 4 5 Row 5 5️⃣ Inner Loop (Stars) for ( j = 1 ; j ...

⓱C Program to Print a Square Pattern

C Program to Print a Square Pattern #include <stdio.h> int main () { int i , j , n ; printf ( "Enter the size of square: " ); scanf ( "%d" , & n ); for ( i = 1 ; i <= n ; i ++ ) // Outer loop for rows { for ( j = 1 ; j <= n ; j ++ ) // Inner loop for columns { printf ( "* " ); } printf ( "\n" ); // Move to next line after one row } return 0 ; } Explanation of Loops 1️⃣ Outer Loop (Row Loop) for ( i = 1 ; i <= n ; i ++ ) Purpose: Controls the number of rows Example if n = 5 Iteration Row Printed i = 1 First row i = 2 Second row i = 3 Third row i = 4 Fourth row i = 5 Fifth row So the outer loop runs n times . 2️⃣ Inner Loop (Column Loop) for ( j = 1 ; j <= n ; j ++ ) Purpose: Prints stars in each row For every row, the inner loop prints n stars. Example for first row: j value Output j = 1 * j = 2 * j = 3 * j = 4...