Selection of a non-random number in a variable C#

Asked

Viewed 62 times

-2

My question is the following proposed exercise: "Task: Write an algorithm in Visualg or C# that takes two positive integer values (x and y) and tell if x is divisible by y. Let’s focus on the problem when y is 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15 or 25."

I wish I had a light where to start.

Once I have access to a computer I will edit the question with my code so far.

EDIT: Code to date:

 namespace  {
     class Program
     {
         static void Main(string[] args)
         {
             //declaração de Variaveis X e Y (onde y é fixa em valores pre definidos e x é dado pelo usuario)
             int x;
             int[,] y = new int [13, 0];
             y[1, 0] = 2;
             y[2, 0] = 3;
             y[3, 0] = 4;
             y[4, 0] = 5;
             y[5, 0] = 6;
             y[6, 0] = 7;
             y[7, 0] = 8;
             y[8, 0] = 9;
             y[9, 0] = 10;
             y[10, 0] = 11;
             y[11, 0] = 12;
             y[12, 0] = 15;
             y[13, 0] = 25;

             //introdução ao programa
             Console.WriteLine("Programa TESTE DE DIVISIBILIDADE");
             Console.WriteLine();
             Console.WriteLine("O programa tem por objetivo informar se um determinado numero é ou não divisivel por outro");
             Console.WriteLine();
             Console.WriteLine("Os testes de divisibilidade são validos para os seguintes divisores: 2,3,4,5,6,7,8,9,10,11,12,15,25");
             Console.WriteLine();
             Console.WriteLine("Aperte qualquer tecla para continuar:");
             Console.ReadKey();
             Console.Clear();

             //coleta de dados
             Console.WriteLine("Digite o Dividendo");
             x = Convert.ToInt32 (Console.ReadLine());
             Console.WriteLine("Digite o Divisor entre 2,3,4,5,6,7,8,9,10,11,12,15,25");
             y = Convert.ToInt32 (Console.ReadLine());


         }
     } 
}
  • To start you declare the variables (var...) then displays a message and reads the two values ( escreva and leia) and then see if the division has as rest zero (num1 ^ num2)

  • Good Afternoon! , yes that would be valid in Visualg, but what about C#? EDIT; code until the moment in question

1 answer

0

Perhaps a static method is the best solution.

using System;

public class Program
{
  public static void Main()
  {
    Console.Write(IsDivisible(3,3));
  }

  public static bool IsDivisible(int x, int y)
  {
    return x % y == 0;
  }
}

Here’s a online test!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.