小编Sab*_*zer的帖子

使用循环计算C#中的阶乘

这是我到目前为止:

namespace factorials
{
    class Program
    {
        static void Main(string[] args)
        {
            int number;

            do
            {
                Console.WriteLine("What non-negative integer do you want to factorial?");
                while (!int.TryParse(Console.ReadLine(), out number))
                    Console.WriteLine("Please enter a whole number only");
                calculate(ref number);
            } while (number >= 0);
            Console.WriteLine("Please enter a non-negative number");

        }
        static void calculate(ref int number)
        {
            int factorial;
            int counter;

            for (counter = number; counter <= number; counter++)
            {
                factorial = number * number;
                Console.WriteLine("The factorial of {0} is {1}", number, factorial);
            } …
Run Code Online (Sandbox Code Playgroud)

c# math loops for-loop

3
推荐指数
1
解决办法
1万
查看次数

从C#中的一系列数字中获取最小值和最大值,而不进行排序

目标是制作一个程序,当输入一系列数字时,显示最小值和最大值.-99将用作哨兵.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            double number = 0, maxValue = 0, minValue = 0;
            string goOn = "Y";

            Console.WriteLine("Please enter a series of numbers, when you wish to stop entering numbers please enter -99.");
            Console.WriteLine("The smallest and largest values will then be displayed.");
            Console.WriteLine("Remember not to enter -99 unless you want the series to end.");
            do
            {
                while (!double.TryParse(Console.ReadLine(), out number))
                    Console.WriteLine("Please enter whole …
Run Code Online (Sandbox Code Playgroud)

c# loops if-statement

1
推荐指数
1
解决办法
2193
查看次数

计算值在数组中出现的次数

那么,用C#创建循环的好方法又简单又好呢?每次在某个数组中出现某个值时,都会在另一个数组中的计数器上加1?

例如我有这个:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication22
{
    class Program
    {
        const int SIZE = 12;

        static void Main(string[] args)
        {
            int[] numbers = new int[SIZE] {5, 5, 5, 7, 7, 7, 9, 7, 9, 9, 9, 1};
           string[] letters = new string[SIZE] { "m", "m", "s", "m", "s", "s", "s", "m", "s", "s", "s", "s" };
            int[] values = new int[SIZE] {15, 22, 67, 45, 12, 21, 24, 51, 90, 60, 50, 44};
            string[] …
Run Code Online (Sandbox Code Playgroud)

c# arrays counter loops

1
推荐指数
1
解决办法
4万
查看次数

标签 统计

c# ×3

loops ×3

arrays ×1

counter ×1

for-loop ×1

if-statement ×1

math ×1