
Nested Loops and Multiplication Tables for Problem Solving
Explore the concept of nested loops in programming with examples such as multiplication tables and triangular numbers. Dive into problem-solving using computers in a CSE classroom environment. Learn how to efficiently use nested for loops for various tasks.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Nesting of for loop One for statement can be nested within another for statement. for (i=0; i< m; ++i) { .. . for (j=0; j < n;++j) { Statement S; } // end of inner for statement }// end of outer for statement 6/3/2025 CSE 1001 Department of CSE 1
Nested loops #include <stdio.h> int main() { int n, number, triangularNumber=0, counter; for ( counter = 1; counter <= 5; counter++ ) { printf( What triangular number do you want? ); scanf( %d ,&number); for ( n = 1; n <= number; n++ ) triangularNumber = triangularNumber + n; printf( The %d th triangular number is %d: ,n- 1,triangularNumber); } return 0; } 6/3/2025 CSE 1001 Department of CSE 2
Example: Multiplication table for n tables up to k terms scanf( %d %d ,&n,&k); for (i=1; i<=k; i++) { for (j=1; j<=n; j++) { prod = i * j; printf( %d * %d = %d\t , j,i,prod); } printf( \n ); } Enter n & k values: 3 5 The table for 3 X 5 is 1 * 1= 1 2 * 1= 2 3 * 1= 3 1 * 2= 2 2 * 2= 4 3 * 2= 6 1 * 3= 3 2 * 3= 6 3 * 3= 9 1 * 4= 4 2 * 4= 8 3 * 4= 12 1 * 5= 5 2 * 5= 10 3 * 5= 15 6/3/2025 CSE 1001 Department of CSE 3
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 03-06-2025 CSE 1001 Problem Solving using Computers (PSUC) - 2018 4