Saturday 21 March 2015

Write program in SQL Server to print pyramid

                    Today,I was reading one of  programming language book .I saw lot of program with respect to pyramids .I always consider it as game of printing some number or  special character.
So I thought why don't I utilize my Saturday with that games.Now we considering that special character as '*'.Lets play with this.We will start with printing pyramids .

Output:
1.



Script :

DECLARE @lclMaxLevel INT=5
DECLARE @lclPrintCount INT =0

WHILE @lclMaxLevel > 0
  BEGIN
      PRINT Space(@lclMaxLevel)
            + Replicate('*', @lclPrintCount)
            + Replicate('*', @lclPrintCount+1)

      SET @lclMaxLevel=@lclMaxLevel - 1
      SET @lclPrintCount=@lclPrintCount + 1
  END

2.
Script :
DECLARE @lclMaxLevel INT=5
DECLARE @lclPrintCount INT =0

WHILE @lclMaxLevel > 0
  BEGIN
      PRINT Space(@lclMaxLevel)
            + Replicate('*', @lclPrintCount+1)

      SET @lclMaxLevel=@lclMaxLevel - 1
      SET @lclPrintCount=@lclPrintCount + 1
  END

  Please give your feedback if you liked it.

No comments:

Post a Comment

First Database In Sql Server