我想知道如果一個數字可以被兩個數字整除,代碼的外觀如何。例15既是雙方3和5如果一個num可以被兩個數字邏輯C整除#
整除那我就可以說
Console.WriteLine("This Number is Divisible by 3 and 5!");
我如何去了解編碼這一點,在那裏我會到位了嗎?請幫忙。
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Enter A Number :");
n = int.Parse(Console.ReadLine());
if (n % 3 == 0)
{
Console.WriteLine("This Number is Divisible by 3 ");
}
else
{
Console.WriteLine("This Number is Not Divisible by 3");
}
Console.ReadLine();
}
}
}
你只需要檢查這個數字是被3整除和5或任何其他數字也?或者像2,3,4,5等特定範圍的數字? –
不清楚你在問什麼。爲什麼你不能在你的例子中檢查數字是否可以被15整除?這個問題似乎是關於數學,而不是編程。請更具體地說明你在解決問題時遇到的困難。 –
要更清楚一點,如果我輸入數字9,我希望它說「這個數字可以被3整除」,如果我輸入數字10,我希望它說「這個數字可以被5整除」,最後如果我輸入一個像15這樣的數字我希望它說「這個數字可以被3和5整除」。 – Kai