Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool suma(int n,int s)
- {
- int nr=0;
- while(n)
- nr+=n%10,n/=10;
- if(nr==s)
- return true;
- return false;
- }
- int main()
- {
- int n,s;
- cin>>n>>s;
- int Min=1,Max=9;
- for(int i=2;i<=n;++i)
- Min=Min*10+0,Max=Max*10+9;
- int nr=0;
- for(int i=Min;i<=Max;++i)
- if(suma(i,s))
- ++nr,cout<<i<<' ';
- if(nr)
- cout<<'\n';
- cout<<nr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement