C# :: Aufgabe #318

3 Lösungen Lösungen öffentlich

Quadratzahlen zwischen 1 und 100

Anfänger - C# von DeinError404 - 30.04.2020 um 23:42 Uhr
Schreibe ein kleines Programm, das die Quadratzahlen zwischen 1 und 100 ausgibt. (Nicht die ersten 100 Quadratzahlen, die Aufgabe gibt es schon.)

Lösungen:

vote_ok
von JKooP (18090 Punkte) - 01.06.2020 um 09:01 Uhr
NET Core 3.x

Quellcode ausblenden C#-Code
namespace CS_Aufgabe_318_Quadratzahlen
{
    class Program
    {
        static void Main(string[] args)
        {
            var i = 1;
            while (i * i <= 100)
                Console.WriteLine($"{i, 2} : {i * i++, 3}");
        }
    }
}
vote_ok
von JKooP (18090 Punkte) - 27.07.2020 um 08:30 Uhr
Quellcode ausblenden C#-Code
// NET.Core 3.x
// als LINQ- Methodenaufruf

using System;
using System.Linq;

namespace CS_Aufgabe_318_Quadratzahlen
{
    class Program
    {
        static void Main(string[] args)
        {
            Enumerable.Range(1, 10).Where(x => x * x <= 100)
                .Select(x => new { c = x, v = x * x }).ToList()
                .ForEach(x => Console.WriteLine($"{ x.c, 2 } : { x.v, 3 }"));
        }
    }
}
vote_ok
von MoSicc (140 Punkte) - 25.08.2020 um 15:57 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;

namespace QuadratzahlenZwischen100
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> Quadrats = new List<int>();

            for(int i = 1; i<=100; i++)
            {
                int y = i * i;
                if (y<100)
                {
                    Quadrats.Add(y);
                }
            }
            foreach(var item in Quadrats)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
    }
}