0% found this document useful (0 votes)
6 views7 pages

Week6 Lec16 17 NestedLoops Ch6 Fa24

Uploaded by

menkahotwani446
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Week6 Lec16 17 NestedLoops Ch6 Fa24

Uploaded by

menkahotwani446
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSC1103: Fundamentals of Programming [ C ]

Week 6

Fall 2024
Sheikh Usama Khalid
Department of Computer Science
100 Building, Clifton, Room 301
[email protected]
Lecture Plan
• Chapter 6: Loops
Fundamentals of Programming

• Programming Review
Fundamentals of Programming

Chapter 6: Loops
Topic: Nested Loops
Fundamentals of Programming

Topic: Nested Loops


Programming Review
Nested Loop for a Rectangular Pattern
#include <stdio.h>

int main() {
int rows = 4;
int columns = 5;
int i,j;

for (i = 1; i <= rows; i++) {


for (j = 1; j <= columns; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

The outer loop controls the number of rows, and the inner loop controls the number of
columns in each row.
Nested Loop for a Right-Angled Triangle
Pattern
#include <stdio.h>

int main() {
int rows = 5, i, j;

for (i = 1; i <= rows; i++) {


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

return 0;
}

The outer loop controls the number of rows, and the inner loop controls the number of
columns in each row.
Nested Loop for Multiplication Table
#include <stdio.h>

int main() {
int n = 5,i,j;

for (i = 1; i <= 10; i++) {


for (j = 1; j <= n; j++) {
printf("%d x %d = %d\t", j, i, i * j);
}
printf("\n");
}

return 0;
}

The outer loop controls the number of rows, and the inner loop controls the number of
columns in each row.

You might also like