Exercise
Multiples
Objetive
Write a C# program to display on the screen the numbers from 1 to 500 that are multiples of both 3 and 5. (Hint: Use the modulo operator to check for divisibility by both 3 and 5.)
Example Code
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
// Using a for loop to iterate through numbers from 1 to 500
for (int i = 1; i <= 500; i++) // Looping through numbers 1 to 500
{
// Checking if the current number is divisible by both 3 and 5
if (i % 3 == 0 && i % 5 == 0) // If the remainder of i divided by 3 and 5 is zero
{
// Displaying the number if it is divisible by both 3 and 5
Console.WriteLine(i); // Printing the number on the screen
}
}
}
}