【发布时间】:2019-05-10 05:14:42
【问题描述】:
我正在学习 C# 编程。 不过,我不知道如何解决这些问题。
像 (写一个 MyAvg 方法,获取 3 个不同的双输入并计算它们的平均值。它应该返回平均值作为输出。在一个简单的程序中使用该函数)
using System;
/*4. Write a MyAvg method that gets 3 different double inputs and calculates the average of them. It should return the average as the output. Use the function in one simple program*/
namespace ConsoleApp36
{
class Program
{
static void Main(string[] args)
{
double a, b, c;
double avg = 0;
Console.Write("Input the first value : ");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Input the second value : ");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Input the third value : ");
c = Convert.ToDouble(Console.ReadLine());
avg = (a + b + c) / 3;
Console.WriteLine("Average of 3 different values is : {0}", avg);
}
}
}
和
(编写一个 MyFact 函数,获取一个整数作为输入并计算它的阶乘。它返回阶乘作为函数的结果。在一个简单的程序中使用该函数。在一个简单的程序中使用该函数.)
using System;
/*4. Write a MyAvg method that gets 3 different double inputs and calculates the average of them. It should return the average as the output. Use the function in one simple program*/
namespace ConsoleApp39
{
class Program
{
static void Main(string[] args)
{
int i, f = 1, num;
Console.Write("Input the number : ");
num = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= num; i++)
f = f * i;
Console.Write("The Factorial of {0} is: {1}\n", num, f);
}
}
}
你们能帮帮我吗?
【问题讨论】:
-
你自己试过了吗?如果您已经写了一些东西,那么提供帮助会更容易。
-
是的,我试过了.. 但我不明白 MyAvg 和 MyFact 是什么意思
-
这只是您必须编写的方法的名称。喜欢
public int MyFact(int input) -
嗨 Seoyoung,欢迎来到 Stack Overflow。不幸的是,SO 想要更具体和实际有问题的问题,因为 C#、.NET 等的基本学习可能比问答网站更适合教学环境。但是,您是否知道 Stack Overflow 附带一整套聊天室?这些比较悠闲,可以接受更多“松散的问题”。您应该在 C# 聊天室中询问,找到 here。
-
我放了一些我自己的代码.. 但我仍然不知道如何制作 Myfact 和 Myavg 的方法(以及“返回”是什么意思?)