C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: We loop through all the frequencies at an increment of 200. This produces a musical effect over a few seconds when executed.
C# program that uses Console.Beep method
using System;
class Program
{
static void Main()
{
// The official music of The Dev Codes.
for (int i = 37; i <= 32767; i += 200)
{
Console.Beep(i, 100);
}
}
}
Note: The Console.Beep method is not supported on some versions of 64-bit Windows. Thanks to Max for writing in with this information.
Then: It waits sixty seconds using Thread.Sleep for each minute, and writes some characters to the screen. Finally it beeps ten times.
int.ParseThread.SleepC# program that implements alarm
using System;
using System.Threading;
class Program
{
static void Main()
{
// Ask for minutes.
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Minutes?");
string minutes = Console.ReadLine();
int mins = int.Parse(minutes);
for (int i = 0; i < mins; i++)
{
// Sixty seconds is one minute.
Thread.Sleep(1000 * 60);
// Write line.
Console.WriteLine(new string('X', 30));
}
// Beep ten times.
for (int i = 0; i < 10; i++)
{
Console.Beep();
}
Console.WriteLine("[Done]");
Console.Read();
}
}