Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int SumaVecih(int n)
- {
- int cifra, suma(0);
- while(n!=0)
- {
- cifra=n%10;
- if(cifra>5){
- suma+=cifra;
- n/=10;
- }
- else{
- n/=10; continue;}
- }
- return suma;
- }
- int SumaManjih(int n)
- {
- int cifra, suma(0);
- while(n!=0)
- {
- cifra=n%10;
- if(cifra<5){
- suma+=cifra;
- n/=10;
- }
- else{
- n/=10; continue;}
- }
- return suma;
- }
- void SumeCifara(int n, int &veci, int &manji)
- {
- veci=SumaVecih(n);
- manji=SumaManjih(n);
- }
- int main()
- {
- int n, a, b;
- std::cout<<"Unesi broj: ";
- std::cin>>n;
- SumeCifara(n, a, b);
- std::cout<<std::endl<<"Suma cifara većih od 5: "<<a
- <<std::endl<<"Suma cifara manjih od 5: "<<b;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement