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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amandeep SinghPosted Sep 24, 2013, 3:29 AM
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:
Hemant SrivastavaPosted Sep 23, 2013, 9:25 AM
VulpesPosted Sep 20, 2013, 2:46 PM
Hemant SrivastavaPosted Sep 20, 2013, 2:41 PM
VulpesPosted Sep 20, 2013, 1:37 PM
Hemant SrivastavaPosted Sep 20, 2013, 10:34 AM
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();
}