Найти все натуральные числа, не превосходящие заданного n, которые делятся на каждую из своих цифр — C++(Си)

#include <iostream>

using namespace std;
 
int main ()
{
    int i, temp, j, n;
 
    cout<<"Vvedite n: "<<endl;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        temp=0;
        j=i;
        while(j>0)
        {
            if(j%10!=0)
            {
                if(i%(j%10)!=0)
                    temp=1;
            }
            else
                temp=1;
            j/=10;
        }
        if(temp==0)
            cout<<i<<endl;
    }
    system("pause");
    return 0; 
}

Leave a Comment