Multiples Learn programming C# Sharp

Lesson:

Flow Control


Exercise:

Multiples 14


Objetive:

Create a C# program to write on screen the numbers from 1 to 500 that are multiples of 3 and also multiples of 5 (hint: use the remainder of the division).


Code:

using System;
public class Exercise28
{
    public static void Main()
    {
        int i = 1;

        while (i <= 500)
        {
            if ((i % 3 == 0) && (i % 5 == 0))
                Console.Write("{0} ", i);

            i++;
        }
    }
}

'Multiples 3 and 5 for

using System;
'Multiples
public class Exercise28
{
    public static void Main()
    {
        int i = 1;

        for (i = 1; i <= 500; i++)
        {
            if ((i % 3 == 0) && (i % 5 == 0))
                Console.Write("{0} ", i);
        }
    }
}

'Multiples 3 and 5 for step 15

using System;
'Multiples
public class Exercise28
{
    public static void Main()
    {
        for (int i = 15; i <= 500; i += 15)
            Console.Write("{0} ", i);
    }
}