Neste algoritmo vamos quebrar um Número inteiro de 5 'casas' Ex: 34567 utilizando a Divisão e Resto das operações e grava-los nas seguintes Variáveis: a, b, c, d, e.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DivisaoResto
{
class Program
{
static void Main(string[] args)
{
int n, a, b, c, d, e;
Console.WriteLine("------------------------------------");
Console.WriteLine("Digite um inteiro de 5 numeros: ");
Console.WriteLine("------------------------------------");
n = Convert.ToInt32(Console.ReadLine());
a = (n / 100) / 100;
b = ((n / 10) / 100) % 10;
c = (n / 100) % 10;
d = ((n / 10) % 100) % 10;
e = (n % 100) % 10;
Console.WriteLine("------------------------------------");
Console.WriteLine("\n\n" + a);
Console.WriteLine("\n\n" + b);
Console.WriteLine("\n\n" + c);
Console.WriteLine("\n\n" + d);
Console.WriteLine("\n\n" + e);
Console.WriteLine("------------------------------------");
Console.ReadKey();
}
}
}
0 Comentários