Va rog frumos, cine stie problemele 1 si 2 din imagine.
Ofer coronița
Răspunsuri la întrebare
Răspuns:
1. #include <iostream>
using namespace std;
int main()
{
int numarCurent = 0, contor1 = 0, contor2 = 0, nrElemente = 0, suma2 = 0;
float suma1 = 0, medie = 0;
cin >> numarCurent;
while( numarCurent != 10 )
{
if( numarCurent >= 20 && numarCurent <= 122 )
{
++contor1;
}
if( numarCurent % 5 == 2 )
{
suma1 += numarCurent;
++nrElemente;
}
if( numarCurent >= 10 && numarCurent <= 99 )
{
suma2 += numarCurent;
}
cin >> numarCurent;
}
if( nrElemente == 0 )
medie = 0;
else
medie = suma1 / nrElemente;
cout << contor1 << " " << medie << " " << suma2;
return 0;
}
2. #include <iostream>
using namespace std;
bool ePalindrom( int x )
{
int copie = x, invers = 0;
while( copie != 0 )
{
invers = invers * 10 + copie % 10;
copie /= 10;
}
if( x == invers )
return true;
else
return false;
}
bool douaCifrePare( int x )
{
int contor = 0;
while( x != 0 )
{
if( ( x % 10 ) % 2 == 0 )
{
++contor;
}
x /= 10;
}
if( contor == 2 )
return true;
else
return false;
}
bool areSaseSiCinci( int x )
{
bool sase = false, cinci = false;
while( x != 0 )
{
if( x % 10 == 5 )
cinci = true;
else if ( x % 10 == 6 )
sase = true;
x /= 10;
}
if( cinci == true && sase == true )
return true;
else
return false;
}
int main()
{
int numarCurent = 0, produsPal = 1, nrDouaCifrePare = 0, sumaCinciSase = 0;
cin >> numarCurent;
while( numarCurent != 100 )
{
if( ePalindrom( numarCurent ) )
produsPal *= numarCurent;
if( douaCifrePare( numarCurent ) )
++nrDouaCifrePare;
if( areSaseSiCinci( numarCurent ) )
sumaCinciSase += numarCurent;
cin >> numarCurent;
}
cout << produsPal << " " << nrDouaCifrePare << " " << sumaCinciSase;
return 0;
}
Explicație:
Răspuns:
Explicație:
1. #include <iostream>
using namespace std;
int main()
{
int numarCurent = 0, contor1 = 0, contor2 = 0, nrElemente = 0, suma2 = 0;
float suma1 = 0, medie = 0;
cin >> numarCurent;
while( numarCurent != 10 )
{
if( numarCurent >= 20 && numarCurent <= 122 )
{
++contor1;
}
if( numarCurent % 5 == 2 )
{
suma1 += numarCurent;
++nrElemente;
}
if( numarCurent >= 10 && numarCurent <= 99 )
{
suma2 += numarCurent;
}
cin >> numarCurent;
}
if( nrElemente == 0 )
medie = 0;
else
medie = suma1 / nrElemente;
cout << contor1 << " " << medie << " " << suma2;
return 0;
}
2. #include <iostream>
using namespace std;
bool ePalindrom( int x )
{
int copie = x, invers = 0;
while( copie != 0 )
{
invers = invers * 10 + copie % 10;
copie /= 10;
}
if( x == invers )
return true;
else
return false;
}
bool douaCifrePare( int x )
{
int contor = 0;
while( x != 0 )
{
if( ( x % 10 ) % 2 == 0 )
{
++contor;
}
x /= 10;
}
if( contor == 2 )
return true;
else
return false;
}
bool areSaseSiCinci( int x )
{
bool sase = false, cinci = false;
while( x != 0 )
{
if( x % 10 == 5 )
cinci = true;
else if ( x % 10 == 6 )
sase = true;
x /= 10;
}
if( cinci == true && sase == true )
return true;
else
return false;
}
int main()
{
int numarCurent = 0, produsPal = 1, nrDouaCifrePare = 0, sumaCinciSase = 0;
cin >> numarCurent;
while( numarCurent != 100 )
{
if( ePalindrom( numarCurent ) )
produsPal *= numarCurent;
if( douaCifrePare( numarCurent ) )
++nrDouaCifrePare;
if( areSaseSiCinci( numarCurent ) )
sumaCinciSase += numarCurent;
cin >> numarCurent;
}
cout << produsPal << " " << nrDouaCifrePare << " " << sumaCinciSase;
return 0;
}
e corecta scz am nev de pct