

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 \n"); printf("--------------------------------\n"); 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 ("\n"); 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 Questions & Answers
- 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
- 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 to print name inside heart pattern using for loop.
- C Program for Print the pattern by using one loop
- C program to print number series without using any loop
- Print 1 to 100 in C++, without loop and recursion
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Python Program for Print Number series without using any loop
- Python program to print all Disarium numbers between 1 to 100
- Count numbers in a range having GCD of powers of prime factors equal to 1 in C++
- Print all integers that are sum of powers of two given numbers in C++
Advertisements