code for making different types of starformat on traingle form...
iam new to console application help me to create starformat on different traingle shapes
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.
Munesh SharmaPosted Jul 24, 2015, 2:37 AM
Munesh SharmaPosted Jul 24, 2015, 2:36 AM
namespace Triangle
{
class Program
{
static void Main(string[] args)
{
int i, j,m,k=6;
Console.WriteLine();
for (i = 1; i <= 5; i++)
{
for (m = 1; m <= k; m++)
{
Console.Write(" ");
}
for (j = 1; j <= i; j++)
{
Console.Write(" " + "*");
}
for (j = i-1; j >= 1; j--)
{
Console.Write(" " + "*");
}
k--;
Console.WriteLine();
}
Console.Read();
}
}
}
Sample Output
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Ashwani ChaudharyPosted Jul 24, 2015, 2:32 AM
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
int count = 1;
for (int i = 0; i <5; i++)
{
for (int j = 5; j >= i; j--)
{
if (i >= j)
{
for (int b = 1; b <= count; b++)
{
Console.Write("*");
}
count++;
}
else
{
Console.Write(" ");
}
}
for (int k = 1; k <= 5; k++)
{
if (i < k)
Console.Write(" ");
else
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Raja TPosted Jul 24, 2015, 1:41 AM
/*
* C# Program to Display Numbers in the form of Triangle
*/
using System;
class Pascal
{
public static void Main()
{
int[,] arr = new int[8, 8];
for (int i = 0; i < 8; i++)
{
for (int k = 7; k > i; k--)
{ //For loop to print spaces
Console.Write(" ");
}
for (int j = 0; j < i; j++)
{
if (j == 0 || i == j)
{
arr[i, j] = 1;
}
else
{
arr[i, j] = arr[i - 1, j] + arr[i - 1, j - 1];
}
Console.Write(arr[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
More details check out
http://www.sanfoundry.com/csharp-program-numbers-triangle/