This depends on a great many factors. As others have jokingly suggested, some kids will be most interested if you forbid them from doing it. Trying to make them program can be the absolute worst possible approach.

I have a son like that. Telling him "no" is the best way to guarantee that he promptly runs off and tries it. He's been that way since he was born, basically. He nearly got run over at age 2 because I told him to not cross the street without a grownup and he had to know why for himself and promptly ran out into the street -- pulling away from me and his father both, as we were standing on either side of him and we were each holding one of his hands -- and nearly got run over by an oncoming car. I don't think the guy ever saw him.

It can also be influenced by gender. I'm a woman and I have two adult sons. They are talented at getting me interested in "male" games, like Master of Magic, by framing it in terms that appeal to me, such as telling me "It's just like your favorite game, Sim City" and then coaching me on how to play it like a civilization building game instead of a strategy and war game and helping to minimize the pain point of actually going to battle.

One thing I complain about with Sim City is that war never happens, though you have a military base and war has a huge impact on economies in the real world. Yet the game has some completely unrealistic disaster scenarios like aliens invading.

The idea that civilization building happens separate from war is just not realistic. That isn't how the world works.

So I don't really like the battle parts of the Master of Magic, but I don't really like how Sim City de-claws things completely, so to speak. It is possible to play Master of Magic as a civilization building game with war as an annoying side detail that happens like in real life. That works pretty well for me.

So girls and boys may take to programming for different reasons. In spite of how not PC it is these days to suggest that girls and boys have some differences, there is some truth to that idea.

I began learning HTML and CSS so I could blog and more effectively talk to people. I like talking to people. A lot of guys learn to code to "do" something and sometimes only grudgingly talk to people to further their goals of "doing" something. Many programmers are very introverted and talking to people is the last thing they want to do.

Some generally useful ideas that may help:

Make sure they have access to computers.

Only restrict their use of computers for safety reasons and in a way that is supportive of them and not punishing or blamey. (My sons were told "No porn and no reading instructions on how to build nuclear weapons." as a tongue in cheek rough guideline and I supplied them with kid-friendly bookmarks to help them get started on things they could look at without worrying too much.)

Follow their interests. If they are interested, take them to the library or the bookstore or whatever and help them find resources that appeal to them, but let it be their thing.

Make it fun. Don't make it another chore they must tick off.

Find ways to connect them with people who program and who enjoy it.

If you have some pigheaded, stubborn kid who hates being told what to do and will do the opposite just because you said "Do x," back way, way, way off on anything that remotely smacks of signaling that "This is something I want you to do." Make sure it is clear in their mind that it is their choice, not yours.