Początkujący programista here, mam za zadanie napisac aplikacje, ktora wyswietla ilość kolejnych liczby podzielnych przez 11 i jednocześnie niepodzielne przez 3.Tylko problem jest taki, że wyświetla mi tylko liczby od 11 do 55, nie ważne jaką ilość liczb do wyświetlenia wpiszę powyżej 5, zatrzymuje się na tym.Próbowałem w warunku pętli zrobić i-1, i wtedy wszystkie liczby normalnie się wyświetlają, tylko jak wpiszę, żeby wyświetlono mi jedną takiego rodzaju liczbę, to mi wyświetla
using System; using System.Collections.Generic; using System.Linq;
namespace ConsoleApp { class Program { static void Main(string[] args) { foreach (int liczba in MySuperNumbers().Take(10)) { Console.WriteLine(liczba); } }
public static IEnumerable MySuperNumbers() { int number = 0, index = 0;
Bez operatora %
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
foreach (int liczba in MySuperNumbers().Take(10))
{
Console.WriteLine(liczba);
}
}
public static IEnumerable MySuperNumbers()
{
int number = 0, index = 0;
while (true)
{
number += 11;
index++;
if (index == 3)
{
index = 0;
continue;
}
yield return number;
}
}
}
}
static void Main(string[] args)
{
int ile = 10;
var query = Enumerable.Range(1, int.MaxValue).Where(x => x % 11 == 0 && x % 3 != 0);
foreach (int liczba in query.Take(ile))
{
Console.WriteLine(liczba);
}
}