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