I have to solve an exercise, and it says:
Do a procedure that receives an integer n positive number. O procedure should print all numbers in the range between 0 and n which are divisible by 2 and 3 (simultaneously).
I'm starting at the moment, and I have little luggage in data structure. I've developed the code below, but it does not return the numbers that are divisible.
using System;
namespace revisao
{
class Program
{
static void Imprimir(int[] vet, int indice)
{
if (indice > 0 && indice < vet.Length)
{
if((vet[indice] % 2 == 0) && (vet[indice] % 3 == 0))
{
Console.Write("{0,3}", vet[indice]);
Imprimir(vet, indice + 1);
}
else
{
Console.Write("Números não divisíveis por 2 e 3 simultaneamente!");
}
}
}
public static void Main(string[] args)
{
int i, tamanho;
Console.Write("Digite o tamanho do vetor: ");
tamanho = Convert.ToInt32(Console.ReadLine());
int[] vetor = new int[tamanho];
for(i = 0; i < vetor.Length; i++)
{
Console.Write("Digite o elemento {0}: ", i);
vetor[i] = Convert.ToInt32(Console.ReadLine());
}
Imprimir(vetor, i);
Console.ReadKey();
}
}
}