用於列印給定數字可以被 3 和 5 整除的所有數字的 C# 程式
要列印可以被 3 和 5 整除的數字,請使用 && 運算子並檢查兩個條件 -
f (num % 3 == 0 && num % 5 == 0) {}如果上述條件為真,那就意味著該數字可以被 3 和 5 整除。
以下是完整程式碼 -
示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int num;
num = 15;
Console.WriteLine("Number: "+num);
// checking if the number is divisible by 3 and 5
if (num % 3 == 0 && num % 5 == 0) {
Console.WriteLine("Divisible by 3 and 5");
} else {
Console.WriteLine("Not divisible by 3 and 5");
}
Console.ReadLine();
}
}
}輸出
Number: 15 Divisible by 3 and 5
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP