Advertisement
naskedvi

S4 - zad.8

Apr 24th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int SumaVecih(int n)
  4. {
  5.     int cifra, suma(0);
  6.     while(n!=0)
  7.     {
  8.         cifra=n%10;
  9.         if(cifra>5){
  10.             suma+=cifra;
  11.             n/=10;
  12.         }
  13.         else{
  14.             n/=10; continue;}
  15.     }
  16.     return suma;
  17. }
  18.  
  19. int SumaManjih(int n)
  20. {
  21.     int cifra, suma(0);
  22.     while(n!=0)
  23.     {
  24.         cifra=n%10;
  25.         if(cifra<5){
  26.             suma+=cifra;
  27.             n/=10;
  28.         }
  29.         else{
  30.             n/=10; continue;}
  31.     }
  32.     return suma;
  33. }
  34.  
  35.  
  36. void SumeCifara(int n, int &veci, int &manji)
  37. {
  38.     veci=SumaVecih(n);
  39.     manji=SumaManjih(n);
  40. }
  41.  
  42. int main()
  43. {
  44.     int n, a, b;
  45.     std::cout<<"Unesi broj: ";
  46.     std::cin>>n;
  47.     SumeCifara(n, a, b);
  48.     std::cout<<std::endl<<"Suma cifara većih od 5: "<<a
  49.              <<std::endl<<"Suma cifara manjih od 5: "<<b;
  50.  
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement