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 - C Tutorial
From the course: C Programming Basics: Flow Control, Variables, and Pointers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Making a decision with if5m 21s
-
(Locked)
Making multiple decisions4m 3s
-
(Locked)
Challenge: Make a decision32s
-
(Locked)
Solution: Make a decision1m 36s
-
(Locked)
Looping with while5m 28s
-
(Locked)
Repeating chunks of code with for3m 25s
-
(Locked)
Challenge: Output a series of numbers30s
-
(Locked)
Solution: Output a series of numbers1m 45s
-
(Locked)
Nested loops2m 50s
-
Understanding functions3m 10s
-
(Locked)
Adding a function4m 12s
-
(Locked)
Passing values to a function2m 28s
-
(Locked)
Challenge: Evaluate a number31s
-
(Locked)
Solution: Evaluate a number1m 16s
-
(Locked)
Returning a value from a function3m 41s
-
-
-
-