From the course: C Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Work the grid - C Tutorial
From the course: C Essential Training
Solution: Work the grid
(upbeat music) - [Instructor] This chapter's course challenge included a lot of individual parts. So I hope you got them all in, and the output is good. Here is my solution, where you see the nested loops down here starting at line 20. Rows are processed in the outer loop. The first inside loop generates the separator row. The second inside loop outputs the values. This loop uses the variable column to count column characters from A through J. These are new variables added to the code. Variable sc counts the number letter rows. I'm sure this task can be done in other ways. But I used a separate variable C, which is initialized back on line 18, zero for the first row. So variable sc tracks the number rows, the letter number combinations, and variable row is the total overall rows. The way to determine which inner loop to execute is done by a mod calculation or expression here at line 24. So this determines whether the…
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 decision3m 37s
-
(Locked)
Exploring the possibilities2m 34s
-
(Locked)
Using the ternary operator3m 1s
-
Working with the switch-case structure4m 9s
-
(Locked)
Challenge: Select an item29s
-
(Locked)
Solution: Select an item57s
-
(Locked)
Creating a for loop3m 58s
-
(Locked)
Setting up a while loop3m 6s
-
(Locked)
Challenge: Repeat some text48s
-
(Locked)
Solution: Repeat some text1m 40s
-
(Locked)
Nesting loops1m 55s
-
(Locked)
Breaking out of a loop3m 28s
-
(Locked)
Avoiding the goto keyword1m 56s
-
(Locked)
Challenge: Work the grid2m 21s
-
(Locked)
Solution: Work the grid2m 8s
-
-
-