Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int n, j, s, nrs, nrd, i, x;
- void citire();
- int suma(int n);
- int main()
- {
- citire();
- int ok=0;
- x=suma(n);
- i=n+1;
- while(suma(i)!=x)
- {
- i++;
- nrd=i;
- }
- cout<<"Cel mai apropiat numar din dreapta:"<<" "<<nrd<<'\n';
- j=n-1;
- while(suma(j)!=x)
- {
- j--;
- if(j==1)
- {
- ok=1;
- break;
- }
- }
- if(ok==0) nrs=j;
- else cout<<"Nu exista!";
- if(ok==0)
- {
- if(nrd-n < n-nrs)
- cout<<nrd;
- else if(nrd-n==n-nrs)
- cout<<nrd<<" "<<nrs;
- else cout<<"Cel mai apropiat numar din stanga:"<<" "<<nrs<<'\n';
- }
- return 0;
- }
- void citire()
- {
- cout<<"Intoruceti nr.: ";
- cin>>n;
- }
- int suma(int n)
- { s=0;
- while(n)
- {
- s=s+n%10;
- n/=10;
- }
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement