你如何在C#中输入一个下降距离公式? [英] How do you enter a Falling Distance Formula in C#

查看:128
本文介绍了你如何在C#中输入一个下降距离公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用C#为一个类项目创建一个程序,它需要我使用公式:



D = 1/2 *(g * t )^ 2



来解决物体的下落距离。



重力(g)是设置为9.8



我尝试过使用int,double和decimal,但这些都不起作用。我已经尝试过研究,但我没有看到任何可以帮助我弄清楚如何输入这个公式。



static void Main(string [] args)

{

Console.WriteLine(请输入时间:);

double t = Convert.ToDouble(Console.ReadLine());



加倍;

双g = 9.8;

双c = .5;





d = c *(t * g)^ 2;

} //结束主要



非常感谢您的帮助。



亲切的问候,



HGonzalez

I am trying to create a program in C# for a class project which requires me to use the formula:

D = 1/2 * (g * t)^ 2

to solve the falling distance of an object.

The gravity (g) is set at 9.8

I have tried using int, double, and decimal, however none of these work. I have tried researching but I have not seen anything that could help me figure out how to enter this formula.

static void Main(string[] args)
{
Console.WriteLine("Please enter time: ");
double t = Convert.ToDouble(Console.ReadLine());

double d;
double g = 9.8;
double c = .5;


d = c * (t * g) ^ 2;
} // end main

Your assistance is appreciated.

Kind regards,

HGonzalez

推荐答案

Console.WriteLine("Please enter time: ");
double t = Convert.ToDouble(Console.ReadLine());

double d;
const double g = 9.8;
const double c = .5;
double squared = Math.Pow((t * g), 2.0);
d = c * squared;

Console.WriteLine(d.ToString());


这篇关于你如何在C#中输入一个下降距离公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆