Blogger templates

Pages

Tuesday, 22 May 2012

Write a C Program to Print The Given Number Pattern by using Nested for Loop

Number_Pattern
 
NESTED FOR STATEMENT:
If one for statement is completely placed with in the other.

POINTS TO REMEMBER:
  • One loop must completely be placed inside the other loop means no overlapping of loops.
  • Each loop must have different variables.
Statement of C Program: This Program prints the Number 5, Five Times; Number 4, Four Times; Number 3, Three Times; Number 2, Two Times; Number 1, Once :


#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
num=5;
clrscr();
printf(" Number Pattern\n);

for( i=num ; i>=1 ; i--)                         
{

for(j=1 ; j<=i ; j++)
{
printf(" %d" , num) ;
}
                                       /* End of j Loop */
printf(" \n");
num-- ;
}
                                      /* End of i Loop */
}                                     /* End of main() */


Output:
 Number Pattern
 5 5 5 5 5
 4 4 4 4
 3 3 3
 2 2
 1


0 comments:

Post a Comment