Home | BAC/Teze | Biblioteca | Jobs | Referate | Horoscop | Muzica | Dex | Games | Barbie

 

Search!

     

 

Index | Forum | E-mail

   

Aceasta pagina de informatica se adreseaza incepatorilor in general, celor care doresc sa se documenteze pe o anumita tema, dar si profesorilor de Informatica interesati, care pot gasi aici prezentari multimedia, in conformitate cu programa MEN, recomandate pentru lectii si predare la clasa.

 

 
 
 
 
 Meniu rapid  Portalul e-scoala | CAMPUS ASLS | Forum discutii | Premii de excelenta | Europa

 

 

 

Inapoi la cuprins

Solutii Capitolul 6

Programul 1

DECLARE FUNCTION p (a, n)

CLS

PRINT " Acest program calculeaza a^n folosind recusivitatea(a natural nenul,n natural)"

DO

 INPUT "Introdu baza( numar natural nenul ) :"; a

 INPUT "Introdu exponentul( numar natural nenul ) :"; n

LOOP WHILE n < 0 OR n <> INT(n) OR a <= 0 OR a <> INT(a)

PRINT

PRINT a; "^"; n; "="; p(a, n)

END

 

FUNCTION p (a, n)

 IF n = 0 THEN

           p = 1

          ELSE

           p = p(a, n - 1) * a

END IF

END FUNCTION

 

Programul 2

DECLARE FUNCTION fib! (n!)

INPUT "Introduceti rangul n:", n

PRINT "Fib("; n; ")="; fib(n)

END

 

FUNCTION fib (n)

  SELECT CASE n

    CASE 0

      fib = 0

    CASE 1

      fib = 1

    CASE ELSE

      fib = fib(n - 1) + fib(n - 2)

  END SELECT

END FUNCTION

 

Programul 3

CLS

FOR x = 1 TO 9

 FOR y = 0 TO 9

  FOR z = 0 TO 9

   IF 34 / (x * x + y * y + z * z) = INT(34 / (x * x + y * y + z * z)) THEN PRINT "34/(x^2+y^2+z^2)="; "34/("; x; "^2+"; y; "^2+"; z; "^2)="; 34 / (x ^ 2 + y ^ 2 + z ^ 2); TAB(60); "xyz="; x; y; z

  NEXT z

 NEXT y

NEXT x

END

 

Programul 4

DEFLNG A-Z

CLS

DO

 INPUT "Introduceti numaratorul fractiei :"; nr

 INPUT "Introduceti numitorul fractiei :"; num

 IF num = 0 THEN PRINT "--- NUMITORUL NU POATE FI 0 ---"

 PRINT

 IF nr >= 0 AND num >= 0 THEN EXIT DO

LOOP

d = nr

i = num

r = 0

q = 0

DO

 q = d \ i

 r = d MOD i

 IF r = 0 THEN EXIT DO

 d = i

 i = r

LOOP

IF i = 1 THEN

           PRINT "Fractia este ireductibila !"

           END

END IF

PRINT "i="; i

CLS

PRINT "Fractia dvs. :"; nr; " / "; num; " a devenit :"; nr / i; "/"; num / i

END

 

Programul 5

CLS

DO

 INPUT "Introdu numarul de degete ale stogianului:", ds

 IF ds > 1 AND ds = INT(ds) THEN EXIT DO

LOOP

DO

 INPUT "Introdu cifrele indicate de stogian:", n

 IF n >= 0 AND n = INT(n) THEN EXIT DO

LOOP

q$ = STR$(n)

l = LEN(q$) - 1

DIM c(1 TO l + 2)

FOR i = 2 TO l + 1

 c(i) = VAL(MID$(q$, i, 1))

 IF c(i) >= ds THEN

                PRINT "Pentru stogian"; c(i); "nu este cifra."

                END

 END IF

NEXT i

DO

 INPUT "Introduceti numarul de degete ale flexianului:", df

 IF df > 1 AND df = INT(df) THEN EXIT DO

LOOP

bz = 0

e = 0

FOR i = l + 1 TO 2 STEP -1

 bz = bz + c(i) * ds ^ e

 e = e + 1

NEXT i

e = 0

DO

 IF bz <= df ^ e THEN EXIT DO

 e = e + 1

LOOP

DIM cif(1 TO e + 4)

j = 0

PRINT "Numarul indicat de stogian este transformat in baza 10:"; bz

nl = bz

PRINT

DO

 j = j + 1

 cif(j) = nl - df * INT(nl / df)

 nl = INT(nl / df)

 IF nl = 0 THEN EXIT DO

LOOP

PRINT "Numarul cautat este:"

FOR i = j TO 1 STEP -1

 PRINT cif(i);

NEXT i

END

 

Programul 6

DECLARE SUB num ()

DIM SHARED n, r, k, a, q$, l

CLS

DO

 INPUT "Introduceti numarul natural n:", n

 INPUT "Introduceti numarul natural r:", r

 IF n >= 0 AND n = INT(n) AND r >= 0 AND r = INT(r) THEN EXIT DO

LOOP

l = LEN(STR$(n)) - 1

DIM SHARED cif(1 TO l + 3)

SELECT CASE r

 CASE IS > l

  PRINT "Trebuie sa iau din numarul n mai multe cifre decat are acesta!!!"

  END

 CASE 0

  IF n = 0 THEN

            PRINT "Numarul cautat este 0."

            END

           ELSE

            CALL num

  END IF

 CASE l

  PRINT "Daca iau"; r; "cifre din numarul"; n; "nu mai am nici o cifra!!!"

  END

 CASE ELSE

 CALL num

END SELECT

END

 

SUB num

  q$ = STR$(n)

  a = l - r

  PRINT "Numarul are  urmatoarele cifre:";

  FOR i = 2 TO l + 1

   cif(i) = VAL(MID$(q$, i, 1))

   PRINT cif(i);

  NEXT i

DO

 sw = 0

 FOR i = 2 TO l + 2

  IF cif(i) < cif(i + 1) THEN

                          SWAP cif(i), cif(i + 1)

                          sw = 1

  END IF

 NEXT i

 IF sw = 0 THEN EXIT DO

LOOP

PRINT

PRINT "Numarul cautat este:";

k = 0

e = a - 1

FOR i = 2 TO a + 1

 k = k + cif(i) * 10 ^ e

 e = e - 1

NEXT i

PRINT k; "."

END SUB

 

Programul 7

DECLARE SUB num ()

DIM SHARED n, r, k, a, q$, l

CLS

DO

 INPUT "Introduceti numarul natural n:", n

 INPUT "Introduceti numarul natural r:", r

 IF n >= 0 AND n = INT(n) AND r >= 0 AND r = INT(r) THEN EXIT DO

LOOP

l = LEN(STR$(n)) - 1

DIM SHARED cif(1 TO l + 3)

SELECT CASE r

 CASE IS > l

  PRINT "Trebuie sa iau din numarul n mai multe cifre decat are acesta!!!"

  END

 CASE 0

  IF n = 0 THEN

            PRINT "Numarul cautat este 0."

            END

           ELSE

            CALL num

  END IF

 CASE l

  PRINT "Daca iau"; r; "cifre din numarul"; n; "nu mai am nici o cifra!!!"

  END

 CASE ELSE

 CALL num

END SELECT

END

 

SUB num

  q$ = STR$(n)

  a = l - r

  PRINT "Numarul are  urmatoarele cifre:";

  FOR i = 1 TO l

   cif(i) = VAL(MID$(q$, i + 1, 1))

   PRINT cif(i);

  NEXT i

  DIM M(a, l)

  FOR i = 1 TO l

   M(1, i) = cif(i)

   FOR j = 2 TO a

    M(j, i) = -1

    FOR k = 1 TO i - 1

     IF M(j - 1, k) > M(j, i) THEN M(j, i) = M(j - 1, k)

    NEXT

    M(j, i) = M(j, i) * 10 + cif(i)

  NEXT j, i

PRINT

max = -1

FOR i = 1 TO l

 IF max < M(a, i) THEN max = M(a, i)

NEXT

PRINT "Numarul cautat este:";

PRINT max; "."

END SUB

 

Programul 8

DECLARE SUB afis (isol!)

DECLARE SUB scrie (numar!, isol!, ia!)

CLS

DIM SHARED n

DO

 INPUT "Introdu un numar natural nenul:"; n

LOOP UNTIL n = INT(n) AND n > 0

DIM SHARED prim(10000)

DIM SHARED sol(10000)

DIM SHARED ind, sw

sw = 0

prim(1) = 2

ind = 1

FOR i = 2 TO n

 sw = 1

 FOR j = 2 TO SQR(i) + 1

  IF i MOD j = 0 THEN

                  sw = 0

                  EXIT FOR

  END IF

 NEXT

 IF sw = 1 THEN

        ind = ind + 1

        prim(ind) = i

 END IF

NEXT i

CLS

 PRINT "Numerele prime <= decat "; n; " sunt:"

 FOR i = 1 TO ind

  IF prim(i) <= n THEN PRINT prim(i); "  ";

 NEXT i

 PRINT

 scrie n, 1, 1

 IF sw = 0 THEN PRINT "Numarul "; n; " nu se poate scrie ca suma de numere prime distincte!"

END

 

SUB afis (isol!)

 sw = 1

 PRINT n; "=";

 PRINT sol(1);

 FOR i = 2 TO isol!

  PRINT "+"; sol(i);

 NEXT i

 PRINT

END SUB

 

SUB scrie (numar!, isol!, ia!)

FOR i = ia! TO ind!

  sol(isol!) = prim(i)

  IF numar > prim(i) THEN

                      scrie numar - prim(i), isol! + 1, i + 1

                     ELSE

                      IF numar = prim(i) THEN

                                          afis isol!

                                         ELSE

                                          EXIT FOR

                      END IF

 END IF

NEXT i

END SUB

 

Programul 9

DECLARE FUNCTION iscon! (A$, I!)

DECLARE FUNCTION isvoc! (A$, I!)

DIM SHARED voc(6) AS STRING * 1

voc(1) = "A"

voc(2) = "E"

voc(3) = "I"

voc(4) = "O"

voc(5) = "U"

voc(6) = "Y"

INPUT "Introduceti textul necodificat:", A$

N = LEN(A$)

FOR I = 1 TO N

  IF NOT (isvoc(A$, I) OR iscon(A$, I) OR MID$(A$, I, 1) = " ") THEN

    PRINT "Nu ati introdus un text in conditiile problemei."

    END

  END IF

NEXT

I = 1

B$ = ""

DO

  IF I < N THEN

    IF iscon(A$, I) AND isvoc(A$, I + 1) THEN

      B$ = B$ + "S" + MID$(A$, I + 1, 1) + MID$(A$, I, 1) + "O"

      I = I + 2

    ELSE

      B$ = B$ + MID$(A$, I, 1)

      I = I + 1

    END IF

  ELSE

    B$ = B$ + MID$(A$, I, 1)

    I = I + 1

   

  END IF

LOOP UNTIL I > N

PRINT A$; " ---> "; B$

INPUT "Introduceti textul codificat:", A$

B$ = ""

I = 1

N = LEN(A$)

DO

  IF I < N - 2 THEN

    IF MID$(A$, I, 1) = "S" AND isvoc(A$, I + 1) AND iscon(A$, I + 2) AND MID$(A$, I + 3, 1) = "O" THEN

      B$ = B$ + MID$(A$, I + 2, 1) + MID$(A$, I + 1, 1)

      I = I + 4

    ELSE

      B$ = B$ + MID$(A$, I, 1)

      I = I + 1

    END IF

  ELSE

    B$ = B$ + MID$(A$, I, 1)

    I = I + 1

  END IF

LOOP UNTIL I > N

PRINT A$; " ---> "; B$

END

 

FUNCTION iscon (A$, I)

  iscon = NOT isvoc(A$, I) AND MID$(A$, I, 1) > "A" AND MID$(A$, I, 1) < "Z"

END FUNCTION

 

FUNCTION isvoc (A$, I)

  FOR j = 1 TO 6

    IF voc(j) = MID$(A$, I, 1) THEN

      isvoc = -1

      EXIT FUNCTION

    END IF

  NEXT

  isvoc = 0

END FUNCTION

 

Programul 10

CLS

INPUT "Introduceti numele fisierului de intrare:", si$

OPEN si$ FOR INPUT AS #1

INPUT #1, n

CLOSE #1

DIM nr(1 TO n), a(n - 1, 1 TO n), lj(n - 1, 1 TO n), st(1 TO n)

FOR i = 1 TO n

  INPUT #1, nr(i)

NEXT

FOR i = 1 TO n

  FOR j = 0 TO n - 1

    li(j, i) = 0

    lj(j, i) = 0

NEXT j, i

FOR j = 1 TO n

  FOR i = 0 TO n - 1

    a(i, j) = -1

    IF nr(j) MOD n = i THEN a(i, j) = nr(j)

    h = i - (nr(j) MOD n)

    IF h < 0 THEN h = h + n

    FOR k = 1 TO j - 1

      IF a(h, k) > 0 AND a(i, j) < a(h, k) + nr(j) THEN

        a(i, j) = a(h, k) + nr(j)

        lj(i, j) = k

      END IF

    NEXT

NEXT i, j

max = -1

h = 0

FOR i = 1 TO n

  IF a(0, i) > max THEN

    max = a(0, i)

    h = i

  END IF

NEXT

PRINT "Numarul total de monede:"; max

PRINT "Gramezile alese:"

j = h

i = 0

n1 = 0

DO

  n1 = n1 + 1

  st(n1) = j

  h = i

  i = i - nr(j) MOD n

  IF i < 0 THEN i = i + n

  j = lj(h, j)

LOOP UNTIL j = 0

FOR i = n1 TO 1 STEP -1

  PRINT st(i)

NEXT

END

 

Programul 11

INPUT "n=", n

DIM a(n)

FOR i = 1 TO n

  PRINT "a("; i; ")=";

  INPUT "", a(i)

NEXT

INPUT "m=", m

DIM b(m)

FOR i = 1 TO m

  PRINT "m("; i; ")=";

  INPUT "", b(i)

NEXT

DIM d(n, m)

FOR i = 1 TO n

  FOR j = 1 TO m

    d(i, j) = d(i - 1, j - 1)

    IF a(i) = b(j) THEN d(i, j) = d(i, j) + 1

    IF d(i - 1, j) > d(i, j) THEN d(i, j) = d(i - 1, j)

    IF d(i, j - 1) > d(i, j) THEN d(i, j) = d(i, j - 1)

NEXT j, i

PRINT "Lungimea"; d(n, m)

i = n

j = m

nr = 0

DIM s(d(n, m))

DO UNTIL i = 0 OR j = 0

  IF a(i) = b(j) THEN

    nr = nr + 1

    s(nr) = a(i)

    i = i - 1

    j = j - 1

  ELSEIF d(i - 1, j) = d(i, j) THEN

    i = i - 1

  ELSEIF d(i, j - 1) = d(i, j) THEN

    j = j - 1

  ELSE

    i = i - 1

    j = j - 1

  END IF

LOOP

PRINT "Subsecventa comuna:"

FOR i = nr TO 1 STEP -1

  PRINT s(i);

NEXT

PRINT: END

 

Programul 12

TYPE dreptunghi

        x1 AS INTEGER

        y1 AS INTEGER

        x2 AS INTEGER

        y2 AS INTEGER

END TYPE

DIM d(100) AS dreptunghi, dr AS dreptunghi

nr = 1

INPUT "m=", m

INPUT "n=", n

INPUT "l=", l

dr.x1 = 0

dr.y1 = 0

dr.x2 = m

dr.y2 = n

d(1) = dr

FOR i = 1 TO l

  PRINT "Lovitura"; i; ":"

  INPUT "Introduceti x_lovitura:", x

  INPUT "Introduceti y_lovitura:", y

  nr1 = nr

  FOR k = 1 TO nr

    IF d(k).x1 <= x AND d(k).x2 >= x AND d(k).y1 <= y AND d(k).y2 >= y THEN

      nr1 = nr1 + 1

      d(nr1) = d(k)

      d(nr1).x2 = x

      d(nr1).y2 = y

      nr1 = nr1 + 1

      d(nr1) = d(k)

      d(nr1).x1 = x

      d(nr1).y2 = y

      nr1 = nr1 + 1

      d(nr1) = d(k)

      d(nr1).y1 = 1

      d(nr1).x2 = x

      d(k).x1 = x

      d(k).y1 = x

    END IF

  NEXT

  nr = nr1

NEXT

max = 0

FOR i = 1 TO nr

  aria = (d(i).x2 - d(i).x1) * (d(i).y2 - d(i).y1)

  IF aria > max THEN max = aria

NEXT

PRINT "Dreptunghiul maximal ramas are aria de"; max; "de unitati."

END   

 

Home | BAC/Teze | Biblioteca | Referate | Games | Horoscop | Muzica | Versuri | Limbi straine | DEX

Modele CV | Wallpaper | Download gratuit | JOB & CARIERA | Harti | Bancuri si perle | Jocuri Barbie

Iluzii optice | Romana | Geografie | Chimie | Biologie | Engleza | Psihologie | Economie | Istorie | Chat

 

Joburi Studenti JOB-Studenti.ro

Oportunitati si locuri de munca pentru studenti si tineri profesionisti - afla cele mai noi oferte de job!

Online StudentOnlineStudent.ro

Viata in campus: stiri, burse, cazari, cluburi, baluri ale bobocilor - afla totul despre viata in studentie!

Cariere si modele CVStudentCV.ro

Dezvoltare personala pentru tineri - investeste in tine si invata ponturi pentru succesul tau in cariera!

 

 > Contribuie la proiect - Trimite un articol scris de tine

Gazduit de eXtrem computers | Project Manager: Bogdan Gavrila (C)  

 

Toate Drepturile Rezervate - ScoalaOnline Romania