Electron Configuration of an Element of the Periodic Table

Asked

Viewed 212 times

3

I would like to create a program that makes the electronic distribution of atoms, but I’m not sure how to implement it. Would it be like this? you would put the atomic number and it would return you the electronic distribution (K, L, M, N, O, P, Q).

I thought I’d use if’s considering that the layers have a maximum number of electrons:

K = 2
L = 8
M = 18
N = 32
O = 32
P = 18
Q = 8

But there are 2 rules that are:

  1. The last layer cannot have more than 8 electrons
  2. The penultimate layer cannot have more than 18 electrons

These two rules hold all my logic. The question is: Does anyone know a better way to implement this project?

Edit: I got a good part now, but the remaining numbers are the same as the valence one. Can anyone help me correct this mistake?

using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;

   namespace ConsoleApplication5
   {
    class Program
    {
        static void Main(string[] args)
        {

           int z = 53;



            int K = 1, L = 555, M = 555, N = 555, O = 555, P = 555, Q = 555;

            if (z >= 2) { z -= 2; K = 2; } else { K = z; }


            if (z >= 8) { z -= 8; L = 8; }
            if (z < 8) L = z;


            if (z >= 18) { z -= 18; M = 18; }
            if (z <= 8) M = z;


            if (z >= 32) { z -= 32; N = 32; }
            if (z < 32 && z >= 18) { z -= 18; N = 18; }
            if (z <= 8) N = z;


            if (z >= 32) { z -= 32; O = 32; }
            if (z > 32 && z >= 18) { z -= 18; O = 18; }
            if (z <= 8) O = z;


            if (z >= 18) { z -= 18; P = 18; }
            if (z <= 8) P = z;


            if (z >= 8) {z -= 8; Q = 8; }
            if (z <= 8) Q = z;


            Console.WriteLine("Valores:\nK = " + K + "\nL = " + L + "\nM = " + M + "\nN = " + N + "\nO = " + O + "\nP = " + P + "\nQ = " + Q);
            Console.ReadKey(); 

        }
    }
    }
  • Post what you have so far so we can have a more solid basis to formulate a help.

2 answers

2

I made a code that I think will help you.

I haven’t tested it very well, but it will already serve as a basis for you.

Edited:

class Program
{

    enum DefinicaoCamada
    {
        K = 2,
        L = 8,
        M = 18,
        N = 32,
        O = 32,
        P = 18,
        Q = 8
    }

    class Camada
    {
        public DefinicaoCamada defCamada;
        public int eletrons;

        public Camada(DefinicaoCamada defCamada)
        {
            this.defCamada = defCamada;
        }

    }

    static void Main(string[] args)
    {

        int totalEletrons = 53;

        Camada ultima = null;

        List<Camada> listaCamadas = new List<Camada>() {
            new Camada(DefinicaoCamada.K),
            new Camada(DefinicaoCamada.L),
            new Camada(DefinicaoCamada.M),
            new Camada(DefinicaoCamada.N),
            new Camada(DefinicaoCamada.O),
            new Camada(DefinicaoCamada.P),
            new Camada(DefinicaoCamada.Q)
        };

        Camada camadaAtual = listaCamadas[0];
        while (totalEletrons > 0)
        {
            if (camadaAtual.eletrons >= (int)camadaAtual.defCamada)
            {
                camadaAtual = listaCamadas[listaCamadas.IndexOf(camadaAtual) + 1];
            }
            else
            {
                camadaAtual.eletrons++;
                totalEletrons--;
                ultima = camadaAtual;
            }
        }

        int dif = 0;

        if (ultima.eletrons > 18)
        {
            dif = ultima.eletrons - 18;
            ultima.eletrons = 18;
            Camada prox = listaCamadas[listaCamadas.IndexOf(ultima) + 1];
            prox.eletrons = dif;
            ultima = prox;
        }

        if (ultima.eletrons > 8 && ultima.eletrons < 18)
        {
            dif = ultima.eletrons - 8;
            ultima.eletrons = 8;
            Camada prox = listaCamadas[listaCamadas.IndexOf(ultima) + 1];
            prox.eletrons = dif;
        }

        Console.WriteLine("Valores:");
        foreach (Camada c in listaCamadas)
        {
            Console.WriteLine(c.defCamada.ToString() + " = " + c.eletrons);
        }
        Console.ReadKey();
    }
}
  • The problem this way is that it inflicts the two rules of the electronic distribution =P I made an edit in the code, the only problem now is that the layers after the valencia layer give the number of the valencia layer. know how to correct? = P

  • I modified the code. I think it should be all right now.

1

using System;
using System.Collections.Generic;

namespace Eletrons
{
    class Program
    {
        static void Main(string[] args)
        {
            // Passo 1: Detectar qual a última camada cheia.
            int z = 53, i = 0, somaCamadas = 0;
            var arrayCamadas = new int[] { 2, 8, 18, 32, 32, 18, 8 };

            foreach (var camada in arrayCamadas)
            {
                somaCamadas += camada;
                if (z - somaCamadas <= 0) break;
                i++;
            }

            // Até aqui, i é a última camada preenchida com todos os elétrons.
            // Para o exemplo 53, i deverá ser 3.

            // Passo 2: Construir a lista que será retornada.

            var listaRetorno = new List<int>();
            var eletronsFaltantes = z;
            for (int j = 0; j < i; j++)
            {
                listaRetorno.Add(arrayCamadas[j]);
                eletronsFaltantes -= arrayCamadas[j];
            }

            // No exemplo, eletronsFaltantes será 25.
            // A regra de conferência para as duas últimas camadas ocorrerá apenas se i for 
            // maior ou igual a 3.

            if (i >= 3)
            {
                if (eletronsFaltantes - 18 > 0)
                {
                    listaRetorno.Add(18);
                    eletronsFaltantes -= 18;
                }
            }

            listaRetorno.Add(eletronsFaltantes);

            listaRetorno.ForEach(Console.WriteLine);
            Console.ReadKey();
        }
    }
}

For 53, this solution returned K = 2, L = 8, M = 18, N = 18, O = 7. I think it’s right.

Browser other questions tagged

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