Chapter 1.2: C# Intro

Abish Pius
Apr 8, 2021


3 Days in a Row, Let’s Go!

Another Challenge: Prompt for an angle and return the cosine of that angle.

using System;
namespace Challenge{
class Program{
static void Main(string[] args){
// prompt for and get angle
Console.Write("Enter angle in degrees: ");
float angle = float.Parse(Console.ReadLine());
// calculate and print cosine and sine
angle *= (float)Math.PI / 180;
Console.WriteLine("Cosine: " + Math.Cos(angle));
Console.WriteLine("Sine: " + Math.Sin(angle));

This challenge requires designing a console app that can take user input and respond with the appropriate output (and also some Math, no pun intended). The System namespace has the Console.ReadLine() function for doing just this. Finally, need to use the Math library to use PI.



Abish Pius

Data Science Professional, Python Enthusiast, turned LLM Engineer