C# program to print all the numbers divisible by 3 and 5 for a given number


To print the numbers divisible by 3 and 5, use the && operator and check two conditions −

f (num % 3 == 0 && num % 5 == 0) {}

If the above condition is true, that would mean the number is divisible by 3 as well as 5.

The following is the complete code −

Example

 Live Demo

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();
      }
   }
}

Output

Number: 15
Divisible by 3 and 5

Updated on: 20-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements