Pages

Sunday, December 29, 2013

Nested Loop

Write a program that will print Asterisks (*) in following pattern

*******
******
*****
****
***
**
*Input:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<stdio.h>
#include<conio.h>
void main (void)
{
  for(int outer=7; outer >=1; outer--)
 {
   int inner = 1;
    while (inner<= outer)
    {
 printf("*");
 inner++;
    }
 printf("\n");
  }
   getch();
 }// main

Result:

*******
******
*****
****
***
**
*

No comments:

Post a Comment