-1
我有一個任務,從鍵盤輸入不同於0和隨機數k的隨機數。我需要找到奇數+ k的和(如果k也是奇數)。此外,只有在輸入0時鍵入數字時,數字的打字纔會中斷。這是我到目前爲止!所有奇數的總和C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main()
{
int k;
int min;
int max;
int odd = 0;
Console.WriteLine("Enter the value of k: ");
k = int.Parse(Console.ReadLine());
Console.WriteLine("Enter minimum integer: ");
min = int.Parse(Console.ReadLine());
Console.WriteLine("Enter maximum integer: ");
max = int.Parse(Console.ReadLine());
Console.Write("Odd: ");
for (int x = min; x <= max; x++)
{
if (x % 2 != 0)
{
Console.Write(x);
Console.Write(" + ");
odd += x;
}
}
Console.WriteLine();
Console.Write("Odd Numbers + K: ");
Console.WriteLine();
{
if (k % 2 !=0)
{
Console.Write(k);
Console.Write(" + ");
odd += k;
}
}
Console.Write("= ");
Console.Write(odd + "\n");
}
}
這是什麼問題?這裏沒有問題。 – Carcigenicate
現在的問題是程序使用最小和最大值之間的數字,我不知道如何讓用戶輸入數字。 – Puhi123
請編輯問題,以便在評論部分沒有關鍵信息。 –