From the course: C Programming Basics: Flow Control, Variables, and Pointers

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Solution: Output a series of numbers

Solution: Output a series of numbers

(upbeat music) - In my solution I use two integer variables a and b, you could use just one variable for both loops as neither loop interferes with the other but I use a and b. The four loop at line seven sets the value of variable a to one. Then the loop will repeat as long as a is less than or equal to 20 and for each spin, the value of variable a is incremented by one. The sole statement belonging to the loop simply displays the value of variable a and a new line. For the second while loop, I use variable b which is initialized in line 10 to the value negative 10. The loop repeats as long as the value of variable b is less than or equal to 10, and within the loop the two statements the first one prints the value of variable b, and the second one adds two to the value of variable b so that only even values are output. I'll build and run my solution, and let me back up so you can see it. There is one through 20, and…

Contents