Hi friends, my frnd given small thing abt priting numbers in this format.
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
Can u please help me to print like this.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 20, 2013, 6:34 AM EDT
I think, without using graphics you can't create above pattern. Since any Console Print method prints characters horizontally (i.e. row by row),
so numbers in each row should follow any kind of mathematical/ logical series (e.g. Arithmetic Progression, GP, HP, etc..).
For example, we could create pattern (as below), where numbers in each row follow some kind of series.
But the pattern you mentioned in the problem, the numbers follow a series in vertical fashion instead of horizontal.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
The code for the above pattern is:
static void Main()
{
int k = 0;
for (int j = 1; j <= 5; j++)
{
for (int i = 1; i <=j; i++)
{
k++;
Console.Write(k.ToString()+ " ");
}
Console.WriteLine();
}
//Just for the hold screen to see output
Console.Read();
}
VulpesRank #55 · 29.2K reputationPosted Sep 20, 2013, 9:37 AM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 20, 2013, 10:41 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 20, 2013, 10:46 AM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 23, 2013, 5:25 AM EDT
Amandeep Singh10 reputationPosted Sep 23, 2013, 11:29 PM EDT
You can print for any Number By this logic
C# Code :(For value=6 -you can get pattern for any number according to limit value By changing the value of limit variable)
class Program
{
static int lastprint;
static void Main(string[] args)
{
int count = 0;
int limit = 6;
for (int i = 1; i <= limit; i++)
{
for (int j = 1; j <= i; j++)
{
if (j == 1)
{
Console.Write(i + "\t");
count = 1;
lastprint = i;
}
else
{
int a1 = limit - count;
count = count + 1;
int newnum = lastprint + a1;
lastprint = newnum;
Console.Write(newnum + "\t");
}
}
Console.WriteLine("");
lastprint = 0;
}
Console.ReadLine();
}
}
Output window: