60% found this document useful (5 votes)
15K views

Structuri Repetitive Cu Test Final

The document discusses the do-while repetitive structure with final test in C/C++. It provides the syntax of do-while, with the block of instructions executing at least once even if the logical condition is not met. An example shows using do-while to find the minimum digit of a natural number read from keyboard. Another example calculates the product of the first n natural numbers read from a file, outputting the result to a different file.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
60% found this document useful (5 votes)
15K views

Structuri Repetitive Cu Test Final

The document discusses the do-while repetitive structure with final test in C/C++. It provides the syntax of do-while, with the block of instructions executing at least once even if the logical condition is not met. An example shows using do-while to find the minimum digit of a natural number read from keyboard. Another example calculates the product of the first n natural numbers read from a file, outputting the result to a different file.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Structuri repetitive

cu test final

http://informaticasite.ro
Structuri repetitive cu test final
Este codificata, prin instructiunea
do_while.
Evaluatia conditiei se face dupa
executia secventei de operatii si determina
repetarea secventei sau iesirea din
structura Instructiunea

F A Repeta
conditie

Structuri repetitive cu test final

http://informaticasite.ro
Sintaxa instructiunii repetitive cu test
final
do
{ instructiuni

}while(cond_logica);
Secventa (bloc de instructiuni) se executa cat timp conditia logica este
adevarata(expresia genereaza o valoare nenula)
Secventa se executa cel putin odata, chiar daca conditia logica
nu este indeplinita.

http://informaticasite.ro
EX. Se afiseaza, pe ecran, cifra minima a unui numar natural
nenul
a.
Numarul a se citeste de la tastatura.
#include<iostream.h>
void main()
{unsigned int a , min=9,c;
cout<<“a=“;cin>>a;
do
{c=a%10;
if ( c<min) min=c;
a=a/10;
}while(a !=0);
cout<<“cifra
minima=“<<min<<endl;
}

http://informaticasite.ro
Sa se calculeze produsul primelor n nr. naturale. Numarul natural nenul
n se citeste din fisierul date.in iar produsul se va afisa in fisierul
date.out. Se foloseste o structura repetitiva cu test final.

#include<fstream.h>
void main()
{ifstream f(“date.in”)
ofstream g(“date.out”)
unsigned m ,i ,p=1;
f>>m;
i=1
do
{ p=p*i;
i=i+1; // i++
}while(i<=m);
g<<“produsul primelor”<<m;
g<<“numere naturale”<<p;
f.close(); g.close();}
http://informaticasite.ro

You might also like