C# :: Aufgabe #99 :: Lösung #5

12 Lösungen Lösungen öffentlich
#99

Zahlen von 1 bis 100 aufaddieren

Anfänger - C# von Torbo - 15.05.2015 um 14:38 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gauß
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 100;
            for (int i = 0; i < 1; i++)
            {
                a = (a + 1)*a / 2;
            }
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}

#5
vote_ok
von mattthias (260 Punkte) - 20.08.2015 um 11:26 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Onetimepad {
    class Program {
        static void Main(string[] args) {
            string input = Console.ReadLine();
            int inputInt = Int32.Parse(input);
            Console.WriteLine((((Int32)Math.Pow(inputInt, 2)) + inputInt) / 2);
            Console.ReadLine();
        }
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben