- Course
- Arrays
- On-screen circumference
 
 
                    
                        
On-screen circumference
                    
                    
                    
                        Last updated: 
                            8/23/2020
                        
                      
                        
                            ⁃
                            Difficulty: 
                            Intermediate
                        
                    
           
                    Create a C# program that draws a 360 screen circumference. You must calculate the radians taking into account the formula below. Draw the circumference with a 5 position separation between each point, use Console.SetCursorPosition. To calculate the sine and cosine, you can use the mathematical functions Math.Cos and Math.Sin. 
The formula you should use is:
radians = angle * PI / 180
                    
                    Input
                    
                    
                    
                    Output
                    
                                                   XXXXXXXX
                             XX        XX
                            XX          XX
                            X            X
                           X              X
                           X              X
                           X              X
                           X              X
                           X              XX
                           X              X
                           X              X
                           X              X
                            X            X
                            XX          XX
                             XXX       XX
                               XXXXXXXX
                                   X
                    Solution
                    
                   
                    
                    using System;
public class CircunferenceOnScreen
{
    public static void Main(string[] args)
    {
        double x, y;
        double radius;
        for (int i = 0; i < 360; i += 5)
        {
            radius = i * Math.PI / 180.0;
            x = 35 + 8 * Math.Cos(radius);
            y = 10 + 8 * Math.Sin(radius);
            Console.SetCursorPosition((int)x, (int)y);
            Console.Write("X");
        }
        Console.SetCursorPosition(1, 20);
    }
}