
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to print four powers of numbers 1 to 9 using nested for loop
Nested loops consist of one loop placed inside another loop.
An example of a nested for loop is as follows −
for (initialization; condition; operation){ for (initialization; condition; operation){ statement; } statement; }
In this example, the inner loop runs through its full range of iterations for each single iteration of the outer loop.
Example
Following is the C program to print the table of first four powers of numbers 1 to 9 by using nested for loop −
#include <stdio.h> void main(){ int i, j, k, temp,I=1; printf("I\tI^2\tI^3\tI^4
"); printf("--------------------------------
"); for ( i = 1; i < 10; i ++) /* Outer loop */{ for (j = 1; j < 5; j ++) /* 1st level of nesting */{ temp = 1; for(k = 0; k < j; k ++) temp = temp * I; printf ("%d\t", temp); } printf ("
"); I++; } }
Output
When the above program is executed, it produces the following result −
I I^2 I^3 I^4 ----------------------- 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 5 25 125 625 6 36 216 1296 7 49 343 2401 8 64 512 4096 9 81 729 6561
- Related Articles
- Program to print numbers from 1 to 100 without using loop
- How to print a diamond using nested loop using C#?
- C program to display all prime numbers between 1 to N using for loop
- C program to print multiplication table by using for Loop
- C program to print name inside heart pattern using for loop.
- How will you print numbers from 1 to 100 without using loop in C?
- C Program to print numbers from 1 to N without using semicolon
- C Program for Print the pattern by using one loop
- C program to print number series without using any loop
- Write a C program to print the message in reverse order using for loop in strings
- Python Program for Print Number series without using any loop
- Java Program to Compute the Sum of Numbers in a List Using For-Loop
- Print 1 to 100 in C++, without loop and recursion
- How to use nested for loop in JavaScript?
- Java Program to print Number series without using any loop

Advertisements