Advertisement
sellmmaahh

TP-tut5-zad3

Sep 3rd, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. bool StepeniDvojke (int n) {
  8.     for (int i=0; i<20; i++) {
  9.             if (pow(2,i)==n) return 1;
  10.     }
  11.     return 0;
  12. }
  13. bool MiniSuma (int a, int b) {
  14.     int suma1=0,suma2=0;
  15.     while (a!=0) {
  16.             suma1+=a%10;
  17.            a/=10;
  18.     }
  19.     while (b!=0) {
  20.             suma2+=b%10;
  21.             b/=10;
  22.     }
  23.     if (suma1<suma2) return true;
  24.     return false;
  25. }
  26. int main () {
  27.  int niz[10]={12,2,6,55,2,9,7,2,14,8};
  28.  cout<<"Najveci element: "<<*(max_element(niz,niz+10))<<endl;
  29.  
  30.  cout<<"Najmanji element se ponavlja "<<count(niz,niz+10,*(min_element(niz,niz+10)))<<" puta."<<endl;
  31.  cout<<"Brojeva koji su stepeni dvojke ima: "<<count_if(niz,niz+10,StepeniDvojke)<<"."<<endl;
  32.  cout<<"Element sa najmanjom sumom cifara je "<<*(min_element(niz,niz+10,MiniSuma))<<endl;
  33.  return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement