Advertisement
dyamondz

Suma de meitats d'un número relacionades - X84338

Oct 12th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int num,conta=0,separat1=0,separat2=0;
  6.     cin>>num;
  7.     int aux=num;
  8.     if(num!=0){
  9.         while(aux!=0){
  10.         aux/=10;
  11.         ++conta;
  12.         }
  13.     }
  14.     else cout<<"res"<<endl;
  15.     if(conta%2==0 && num!=0){
  16.         int aux2,reduir=num;
  17.         for(int i=0;i<(conta/2);++i){
  18.             aux2=reduir;
  19.             aux2%=10;
  20.             reduir/=10;
  21.             separat2=separat2+aux2;
  22.         }
  23.         for(int i=0;i<(conta/2);++i){
  24.             aux2=reduir;
  25.             aux2%=10;
  26.             reduir/=10;
  27.             separat1+=aux2;
  28.         }
  29.         if(separat1>separat2) cout<<separat1<<" > "<<separat2<<endl;
  30.         else if(separat1<separat2) cout<<separat1<<" < "<<separat2<<endl;
  31.         else cout<<separat1<<" = "<<separat2<<endl;
  32.     }
  33.     else if (conta%2==1) cout<<"res"<<endl;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement