Sunteți pe pagina 1din 3

#include <iostream> using namespace std; int main() { int n, i = 0; cin >> n; while( n !

= 0) { i++; n /= 10; } cout << "nr de cifre al lui n este: " << i; return 0; } b) int i, n; cin>>n; while( n >= 10 ) n /= 10; cout<<"prima cifra a lui n este "<<n; c) float ma = 0; int i = 0, sum = 0, n; cin>>n; while ( n != 0 ){ i++; ma += n % 10; n /= 10; } ma /= i; cout << "media arit. a cifrelor lui n este: " << ma; d) int sum = 0, n; cin>>n; while ( n >= 100 ) n /= 10; sum = n % 10; n /= 10; sum+=n; cout << "suma primelor 2 cifre este: " << sum; e) int aux = 0, maxim, n, maxVect[10] = {0}; cin>>n; maxim = n % 10; maxVect[maxim]++; n /= 10; while ( n != 0 ){ aux = n % 10; maxVect[aux]++; if(aux > maxim) maxim = aux; n /= 10; }

cout << "maximul este: " << maxim << " si apare de: "<< maxVect[maxim]; 2. #include <iostream> using namespace std; int main() { int n, oglindit = 0; cin>>n; while ( n != 0 ){ oglindit = oglindit * 10 + n % 10; n /= 10; } cout << "oglinditul lui n este: " << oglindit; return 0; } 3. #include<iostream> using namespace std; int main() { int n, nr, r, x, i; count<<"n="; cin>>n; nr = 0; x = n; while(x>0) { nr++; x=x/10; } r=0; for(i = 1; i < nr/2;i++) { r = r*10+n%10; n=n/10; } n=n/10; while(r>0) { n=n*10+r%10; r=r/10; } cout<<"nr este: "<< n; } 4. #include <iostream> using namespace std; int main() { int aux, aux2, n, i = 0, j = 0; cin>>n; aux = n; while ( aux != 0 ){ i++;

aux /= 10; } aux = 0; // refolosim o variabila; if( i % 2 != 0){ while( j <= i/2){ j++; aux = n % 10; n = n / 10; } //n = n / 10; cout << aux; } else { aux = 0; aux2 = 0; while( j < i/2 ){ aux = n % 10; j++; n = n / 10; } aux2 = n % 10 * 10 + aux; cout<< aux2 ; } return 0; }