As others have said: practice. You'll want to write "complete" programs as much as possible.
As a beginner, you'll probably have difficulty with just 10 lines of code. But write a bunch of toy problems, and soon you'd be writing 100 lines of code to solve bigger problems. Write a toy program to play "rock-paper-scissors". Write a program to solve the quadratic equation. Write FizzBuzz. A bunch of small stuff.
Grow to ~1000 lines of code, which starts to look like real projects. TicTacToe solver, Checkers. Even a raytracer can be written in under 1000 lines of code
. Maybe a small GUI that helps you play some game or analyze Baseball statistics or something. When you're confident in your skills, try a larger project, something that will take 10,000 lines of code to finish.
To practice 100,000+ lines of code, instead to change something in some open source code that you use a lot. Write a Linux kernel module. Write a plugin to some open source game. Fix that bug in Blender and/or Gimp that's been driving you nuts.