CSharp examples for Language Basics:Math
Generates a sine wave on the console by iterating through the angles from 0 to 360
using System;//from w w w.j a v a2s . c o m public class Program { public static void Main(string[] args) { double twoPI = 2.0 * Math.PI; for(double degrees = 0.0; degrees <= 360.0; degrees += 15.0) { double radian = twoPI * (degrees / 360.0); double sin = Math.Sin(radian); double percentage = (sin + 1.0) / 2.0; int widthInColumns = 79; int target = (int)(widthInColumns * percentage); for (int j = 0; j <= widthInColumns; j++) { char c = ' '; if (j == target) { c = '*'; } Console.Write(c); } Console.WriteLine(); } } }