From the course: C Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Solution: Repeat some text - C Tutorial
From the course: C Essential Training
Solution: Repeat some text
(upbeat music) - [Instructor] To make the loop work in your solution, you need a second variable. I've added variable B to the declaration of variable A here at line five. The for loop appears at line 10. Variable B is initialized to zero. The loop repeats while variable B is less than the value of variable A, which is what the user input. And each time the loop repeats, variable B is incremented. The single repeating statement is putchar here at line 11. I added a second putchar statement here at line 12 to terminate the new line, which helps clean up output. Build and run, and I'll type 50, and you see 50 hyphens. I know it's 50 hyphens, I'm not going to count them. Here's my while loop variation for the solution. It also requires a second variable B, which is initialized here at line 10. And you don't have to call it variable B, but you do need a second variable. The while loop repeats, as long as the value of…
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
-
Exploring the possibilities2m 34s
-
Using the ternary operator3m 1s
-
Working with the switch-case structure4m 9s
-
Challenge: Select an item29s
-
Solution: Select an item57s
-
Creating a for loop3m 58s
-
Setting up a while loop3m 6s
-
Challenge: Repeat some text48s
-
Solution: Repeat some text1m 40s
-
Nesting loops1m 55s
-
Breaking out of a loop3m 28s
-
Avoiding the goto keyword1m 56s
-
Challenge: Work the grid2m 21s
-
Solution: Work the grid2m 8s
-
-
-