Ayuda con este codigo.
Publicado por dario (48 intervenciones) el 04/03/2020 09:00:31
Tengo este enunciado. Es un programa de Coordenadas cartesianas a polares.
Write a program which accepts cartesian coordinates x and y, and prints its polar coordinates form i.e. r and theta (degrees only).
For ex :
1) if user input x=3 and y=5 then it should print r and theta as
5.8309
59.0362
2) if user input x = 20 and y = 34 then it should print r and theta as
39.4462
59.5345
Mi problema es: como imprimo con cuatro decimales sin redondear, hice mi codigo pero en el ejemplo 1 el resultado 5.8309 me lo redondea a 5.831.
Como hago para que no se redondee.
Salu2.
Write a program which accepts cartesian coordinates x and y, and prints its polar coordinates form i.e. r and theta (degrees only).
For ex :
1) if user input x=3 and y=5 then it should print r and theta as
5.8309
59.0362
2) if user input x = 20 and y = 34 then it should print r and theta as
39.4462
59.5345
Mi problema es: como imprimo con cuatro decimales sin redondear, hice mi codigo pero en el ejemplo 1 el resultado 5.8309 me lo redondea a 5.831.
Como hago para que no se redondee.
Salu2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
class Program {
static void Main() {
const double pi = Math.PI;
double x,y,r,theta;
Console.Write("Coordenada X: ");
x = double.Parse(Console.ReadLine());
Console.Write("Coordenada Y: ");
y = double.Parse(Console.ReadLine());
r = Math.Sqrt(Math.Pow(x,2) + Math.Pow(y,2));
theta = Math.Atan(y/x);
theta =theta * (180/pi);
Console.WriteLine(r.ToString("n4"));
Console.WriteLine(theta.ToString("n4"));
}
}
Valora esta pregunta


0