Hi my question is how can i draw a circle in C# console app like this
****
*****
*****
****
im noob in c# console and drawing i always use windows form app but this is only to learn new things of c# not only school class thanks for your help
Loading
VulpesPosted Jul 26, 2014, 10:43 AM
http://stackoverflow.com/questions/24356723/how-to-draw-a-circle-with-asterisk-function-in-ruby
I've translated that to C# and added some code to (optionally) fill the circle with asterisks and the results are quite good:
Yash AroraPosted Jul 16, 2017, 4:36 PM
{
int i, j;
int N = x;
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
//Print corner elements
if ((i == 1 || i == N) && (j == 1 || j == N))
{
Console.Write(" ");
}
else if (i == 1 || i == N || j == 1 || j == N)
{
//Print edges
Console.Write(c);
}
else
{
//Print center
Console.Write(" ");
}
}
Console.Write("\n");
}
Armando QuirogaPosted Jul 26, 2014, 3:56 AM
using System;
using System.Collections.Generic;
using System.Text;
namespace PiramideAsteriscos
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Programa que crea una pirámide de asteriscos");
inicio:
Console.WriteLine("inserta en número el nivel de la pirámide, mayor a cero");
try
{
int nivel = int.Parse(Console.ReadLine());
if (nivel != 0)
{
int a;
int espacios;
for (int i = 1; i <= nivel; i++)
{
StringBuilder final = new StringBuilder();
espacios = nivel - i;
a = i + (i - 1);
for (int i1 = 0; i1 < espacios; i1++)
final.Append(" ");
for (int i2 = 0; i2 < a; i2++)
final.Append("*");
Console.WriteLine(final.ToString());
}
}
else
{
System.Console.Clear();
goto inicio;
}
}
catch (Exception)
{
System.Console.Clear();
Console.WriteLine("El programa solo acepta números enteros");
goto inicio;
}
Console.WriteLine("" + "\n" + "Aprieta una tecla para salir");
Console.ReadLine();
}
}
}
VulpesPosted Jul 23, 2014, 4:30 PM