<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.algopedia.ro/wiki/index.php?action=history&amp;feed=atom&amp;title=Clasa_a_IX-a_lec%C8%9Bia_5</id>
	<title>Clasa a IX-a lecția 5 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.algopedia.ro/wiki/index.php?action=history&amp;feed=atom&amp;title=Clasa_a_IX-a_lec%C8%9Bia_5"/>
	<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_IX-a_lec%C8%9Bia_5&amp;action=history"/>
	<updated>2026-04-13T05:02:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://www.algopedia.ro/wiki/index.php?title=Clasa_a_IX-a_lec%C8%9Bia_5&amp;diff=17968&amp;oldid=prev</id>
		<title>Bella: /* Reguli minime de editare cod */</title>
		<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_IX-a_lec%C8%9Bia_5&amp;diff=17968&amp;oldid=prev"/>
		<updated>2020-10-01T16:04:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Reguli minime de editare cod&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Note de curs: prof. Isabela Coman&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
= Lectie =&lt;br /&gt;
&lt;br /&gt;
== Structura repetitiva &amp;#039;&amp;#039;&amp;#039;while do&amp;#039;&amp;#039;&amp;#039; ==&lt;br /&gt;
Structura repetitivă de tip WHILE-DO (cîtă timp - execută) reprezinta structura de control cu ajutorul careia executam un set de instructiuni, de mai multe ori, in functie de o conditie. Conditia se testeaza imediat la intrarea in structura repetitiva, de aceea, “while-do” se numeste structura repetitiva conditionata anterior.&lt;br /&gt;
&lt;br /&gt;
[[Image:sl-while-do.gif|frame|none|Structura repetitivă de tip WHILE-DO]]&lt;br /&gt;
Pseudocod&lt;br /&gt;
 Cat_timp(cond)executa&lt;br /&gt;
   Prel&lt;br /&gt;
&lt;br /&gt;
C/C++&lt;br /&gt;
 while(cond){&lt;br /&gt;
   Prel;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Mecanism:&lt;br /&gt;
* Pas1. Se testeaza conditia. Daca conditia este adevarata atunci trecem la pasul 2. Daca conditia este falsa se trece la pasul 3&lt;br /&gt;
* Pasul 2: Se executa pachetul de instructiuni “Prel” si se revine la pasul 1.&lt;br /&gt;
* Pasul 3. Stop&lt;br /&gt;
&lt;br /&gt;
== Aplicatii ==&lt;br /&gt;
=== [https://www.pbinfo.ro/?pagina=probleme&amp;amp;id=327 AfisareNumere] ===&lt;br /&gt;
Se dă un număr natural n. Afișați în ordine crescătoare primele n numere naturale nenule.&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Pseudocod&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
    intreg n, i;&lt;br /&gt;
    citeste n;&lt;br /&gt;
    i &amp;lt;- 1; &lt;br /&gt;
    cat_timp( i &amp;lt;= n )      &lt;br /&gt;
      scrie i, &amp;quot; &amp;quot;;&lt;br /&gt;
      i &amp;lt;- i + 1;                   &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;C++&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
    int n, i;&lt;br /&gt;
    cin &amp;gt;&amp;gt; n;&lt;br /&gt;
    i = 1; &lt;br /&gt;
    while( i &amp;lt;= n ){       &lt;br /&gt;
      cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
      i++;                    // i = i + 1;&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Cifra de control ====&lt;br /&gt;
* [https://www.pbinfo.ro/?pagina=probleme&amp;amp;id=340 Cifra de control Pbinfo]&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
  int n;&lt;br /&gt;
  cin &amp;gt;&amp;gt; n;&lt;br /&gt;
  cout &amp;lt;&amp;lt; ( n - 1 ) % 9 + 1;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
  intreg n, s;&lt;br /&gt;
  citeste n;&lt;br /&gt;
  cat timp ( n &amp;gt; 9 ) executa       // cata vreme numarul are mai mult de o cifra&lt;br /&gt;
    s = 0;&lt;br /&gt;
    cat_timp ( n &amp;gt; 0 ) executa&lt;br /&gt;
      s = s + n mod 10;&lt;br /&gt;
      n = n div 10;&lt;br /&gt;
    n = s;&lt;br /&gt;
  scrie n;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, s;&lt;br /&gt;
  cin &amp;gt;&amp;gt; n;&lt;br /&gt;
  while ( n &amp;gt; 9 ){&lt;br /&gt;
    s = 0;&lt;br /&gt;
    while ( n &amp;gt; 0 ){&lt;br /&gt;
      s += n % 10;&lt;br /&gt;
      n = n / 10;&lt;br /&gt;
    }&lt;br /&gt;
    n = s;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; n;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [http://varena.ro/problema/cifra cifra de control]&lt;br /&gt;
&lt;br /&gt;
  intreg n, i, c;&lt;br /&gt;
  citeste n, c;&lt;br /&gt;
  i &amp;lt;- c;&lt;br /&gt;
  while ( i &amp;lt;= n )&lt;br /&gt;
    scrie i, &amp;quot; &amp;quot;;&lt;br /&gt;
    i &amp;lt;- i + 9;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
ifstream fin( &amp;quot;cifra.in&amp;quot; );&lt;br /&gt;
ofstream fout( &amp;quot;cifra.out&amp;quot; );&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, i, c;&lt;br /&gt;
  fin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; c;&lt;br /&gt;
  i = c;&lt;br /&gt;
  while ( i &amp;lt;= n ){&lt;br /&gt;
    fout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    i += 9;&lt;br /&gt;
  }&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LABORATOR ==&lt;br /&gt;
===2 la n ===&lt;br /&gt;
Sa se calculeze 2  la puterea n.&lt;br /&gt;
  intreg n, contor;&lt;br /&gt;
  citeste n;&lt;br /&gt;
  contor = 0; &lt;br /&gt;
  p = 1;&lt;br /&gt;
  while ( contor &amp;lt; n ) &lt;br /&gt;
    p = p * 2;&lt;br /&gt;
    contor &amp;lt;- contor + 1;&lt;br /&gt;
  scrie  p;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  int n, contor;&lt;br /&gt;
  scanf( &amp;quot;%d&amp;quot;, &amp;amp;n );&lt;br /&gt;
  contor = 0; &lt;br /&gt;
  p = 1;&lt;br /&gt;
  while (  contor &amp;lt; n ) {&lt;br /&gt;
    p = p * 2;&lt;br /&gt;
    contor ++;&lt;br /&gt;
  }&lt;br /&gt;
  printf( &amp;quot;%d &amp;quot;, p );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ridicarea la putere se poate face si in timp logaritmic astfel:&lt;br /&gt;
&lt;br /&gt;
*Dacă &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; este par, atunci &amp;lt;tt&amp;gt;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; = a&amp;lt;sup&amp;gt;2*n/2&amp;lt;/sup&amp;gt; = (a&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;)&amp;lt;sup&amp;gt;n/2&amp;lt;/sup&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
*Dacă &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; este impar, atunci &amp;lt;tt&amp;gt;n-1&amp;lt;/tt&amp;gt; este par și avem &amp;lt;tt&amp;gt;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; = a * a&amp;lt;sup&amp;gt;n-1&amp;lt;/sup&amp;gt; =  a * a&amp;lt;sup&amp;gt;2*(n-1)/2&amp;lt;/sup&amp;gt; = a * (a&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;)&amp;lt;sup&amp;gt;(n-1)/2&amp;lt;/sup&amp;gt; = a * (a&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;)&amp;lt;sup&amp;gt;n/2&amp;lt;/sup&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
În formulele de mai sus am considerat că &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; este împărțirea întreagă din limbajul C. Se observă că indiferent de paritatea lui &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, la fiecare pas al iterației putem transforma &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; în &amp;lt;tt&amp;gt;a * a&amp;lt;/tt&amp;gt; și apoi putem împărți &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; la &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;. Doar în cazurile cînd &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; este impar vom acumula valoarea curentă a lui &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; la produsul calculat. Complexitatea acestei soluţii va fi logaritmică, O(log n). Ce înseamnă acest lucru? Că timpul necesar calculului este proporţional cu un număr &amp;#039;&amp;#039;k&amp;#039;&amp;#039;, unde &amp;#039;&amp;#039;k&amp;#039;&amp;#039; este exponentul lui 2 astfel încît &amp;#039;&amp;#039;2&amp;lt;sup&amp;gt;k&amp;lt;/sup&amp;gt;=n&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Iată soluția bazată pe această idee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  int a, n, p;&lt;br /&gt;
&lt;br /&gt;
  scanf( &amp;quot;%d%d&amp;quot;, &amp;amp;a, &amp;amp;n );&lt;br /&gt;
  p = 1;&lt;br /&gt;
  while ( n &amp;gt; 0 ) {&lt;br /&gt;
    if (n % 2 == 1)&lt;br /&gt;
      p = p * a;&lt;br /&gt;
    a = a * a;&lt;br /&gt;
    n = n / 2;&lt;br /&gt;
  }&lt;br /&gt;
  printf( &amp;quot;%d&amp;quot;, p );&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Citire/ scriere in C/c++ ==&lt;br /&gt;
&lt;br /&gt;
* [http://lbi.ro//~bella/9/03%20Elemente%20de%20baza/1_Citire_scriere.pdf Citire/Scriere]&lt;br /&gt;
&lt;br /&gt;
== Instalare codeblocks ==&lt;br /&gt;
&lt;br /&gt;
* Instalați codeblocks [http://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe Code::Blocks].&lt;br /&gt;
&lt;br /&gt;
== Reguli minime de editare cod == &lt;br /&gt;
* acolada care deschide un bloc de intructiuni va fi pe aceeasi linie cu structura care il contine: &lt;br /&gt;
* identarea la 2 spatii, &lt;br /&gt;
&lt;br /&gt;
Ex:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int main() {&lt;br /&gt;
  if ( conditie ) {&lt;br /&gt;
    instructiune1;&lt;br /&gt;
  } &lt;br /&gt;
  else if ( conditie ) {&lt;br /&gt;
    instructiune2;&lt;br /&gt;
  } &lt;br /&gt;
  else {&lt;br /&gt;
    instructiune3;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Tema = &lt;br /&gt;
== TEMA Teorie ==&lt;br /&gt;
* [https://www.pbinfo.ro/?pagina=probleme&amp;amp;id=330 AfisareNumerePare]&lt;br /&gt;
Se dă un număr natural n. Afișați în ordine crescătoare primele n numere naturale pare nenule.&lt;br /&gt;
* [https://www.pbinfo.ro/?pagina=probleme&amp;amp;id=328 AfisareNumere1]&lt;br /&gt;
Se dă un număr natural n. Afișați în ordine descrescătoare primele n numere naturale nenule.&lt;br /&gt;
* [https://www.pbinfo.ro/probleme/331/afisarenumereimpare AfisareNumereImpare]&lt;br /&gt;
Se dă un număr natural n. Afișați în ordine descrescătoare primele n numere naturale impare.&lt;br /&gt;
Se dă un număr natural n. Afișați în ordine crescătoare primele n numere naturale pare nenule.&lt;br /&gt;
* Scrieti in pseudocod algoritmii de rezolvare pentru problema  “palindrom”.&lt;br /&gt;
&lt;br /&gt;
== Tema 5 Laborator ==&lt;br /&gt;
* [http://varena.ro/problema/cangur Cangur] &lt;br /&gt;
* [http://varena.ro/problema/economii Economii]&lt;br /&gt;
* [http://varena.ro/problema/minute Minute]&lt;br /&gt;
* (usoara)  Se citeste un numar n. Afisati numarul rezultat prin eliminarea primei cifre a lui n.&lt;br /&gt;
* (medie)   Se citeste un numar n. Afisati cifra de control a numarul n. Cifra de control se obtine prin adunarea repetata a cifrelor numarului pana cand se obtine o singura cifra.&lt;br /&gt;
Ex: n=193 s=1+9+3=13 s=1+3=4&lt;br /&gt;
* (dificila)Se citeste un numar n. Sa se afiseze cel mai apropiat fata de n numar palindrom.&lt;br /&gt;
Ex1: 122 , afisam 121; nr 122 e cuprins intre 121 si 131, iar 121 este mai apropiat fata de 122&lt;br /&gt;
Ex2: 452 , afisam 454; nr 452 este cuprins intre 444 si 454&lt;br /&gt;
&lt;br /&gt;
=== Suplimentar: ===&lt;br /&gt;
&lt;br /&gt;
Ca aplicatie la ridicarea la putere:&lt;br /&gt;
&lt;br /&gt;
* [http://www.infoarena.ro/problema/modulo modulo]&lt;br /&gt;
&lt;br /&gt;
Probleme OJI :&lt;br /&gt;
&lt;br /&gt;
* [http://varena.ro/runda/oji_2017_9 Runda_OJI]&lt;br /&gt;
* [https://codeforces.com/contest/440/problem/A A. Forgotten Episode]&lt;/div&gt;</summary>
		<author><name>Bella</name></author>
	</entry>
</feed>