👤

Sa se afiseze toate perechile de elemente vecine din vector care au aceeasi suma a cifrelor.
In c++ va rog.


Răspuns :

#include <iostream>

using namespace std;


int main()
{
     int v[30],n,i,x,y;
     cin>>n;
     for(i=0;i<n;i++)
        cin>>v[i];
     for(i=0;i<n;i++)
     {
         int S1=0,S2=0;
         x=v[i];
         y=v[i+1];
         while(x!=0 || y!=0)
         {
             S1=S1+x%10;
             S2=S2+y%10;
             x=x/10;
             y=y/10;
         }
         if(S1==S2)
            cout<<v[i]<<' '<<v[i+1]<<endl;
     }
    return 0;
}