- #1
SGJ
- 10
- 0
Mod note: added code tags
C:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> number = new List<int>(1000); // int list for 1000 numbers
for(int i = 0; i < 1000; i++) // for loop that populates the numbers array
{
number.Add (i + 1); // the first position in the array will equal 1 rather than zero
}
for (int i = 2; i <= 32; i++) // This is the first loop that will run the square root of 1000 times
{
for (int j = 2; j < 32; j++) // Nested for loop that will run for the square root of 1000 times
{
number.Remove(j * i); // every muptiple will be removed leaving only odd numbers
}
foreach (int numbers in number)
{
Console.Write(" " + number.Count); // writes the numbers still left in the list
}
}
Console.ReadKey(); // Keeps program open
}
}
}
Last edited by a moderator: