Jump to content

Rezolvare Exercitiu In Turbo Pascal?


MrTea
Go to solution Solved by Kid Koder,

Recommended Posts

  • Solution

Am facut Pascal acum cativa ani :)) Nu garantez ca urmatorul cod se compileaza

program LoL;

var N, sumcif, i, aux, x: longint;

begin
   writeln("Introduceti N: ");
   readln(N);

   for i:= 1 to N do
     begin
        sumcif := 0;
        aux := i;
        x := i;
        while(aux <> 0) do
           begin
             sumcif := sumcif + aux mod 10;
             aux := aux div 10;
           end
        if (x mod sumcif) then writeln(x);
     end

 end.
  • Upvote 2

Daca iti iese un program din prima, inseamna ca ceva e gresit...

Link to comment
Share on other sites

imi poti explica ce inseamna aux?

 

Am luat o variabila aux, de la auxiliar, in care retineam fiecare numar de la 1 la N (si in x retineam asta), pentru ca dupa ce faceam suma cifrelor in sumcif, aux devenea 0. si eu trebuia sa fac verificarea daca restul impartirii numarului la sumcif este 0 sau nu. Astfel, aux era mai mult o variabila care ma ajuta sa calculez sumcif, fara sa pierd numarul (deoarece acesta se afla in X).

 

PS: Acum imi dau seama ca nu era nevoie de x :)) Puteam sa afisez si sa fac verificarea cu i

Daca iti iese un program din prima, inseamna ca ceva e gresit...

Link to comment
Share on other sites

  • Moderators

Chestia e ca trebuie sa fac in pascal, asa e in informatica de-a 9-a si am cam lipsit 2 saptamani pe cauza de boala si chiar daca mi-a lamurit tot nu am inteles unele functii!

 

Pai la scoala ati facut direct Pascal? N-ati facut intai pseudocod?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.