Advertisement
a53

numeres

a53
May 16th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool suma(int n,int s)
  5. {
  6. int nr=0;
  7. while(n)
  8. nr+=n%10,n/=10;
  9. if(nr==s)
  10. return true;
  11. return false;
  12. }
  13.  
  14. int main()
  15. {
  16. int n,s;
  17. cin>>n>>s;
  18. int Min=1,Max=9;
  19. for(int i=2;i<=n;++i)
  20. Min=Min*10+0,Max=Max*10+9;
  21. int nr=0;
  22. for(int i=Min;i<=Max;++i)
  23. if(suma(i,s))
  24. ++nr,cout<<i<<' ';
  25. if(nr)
  26. cout<<'\n';
  27. cout<<nr;
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement