In this challenge, you must code a program that repeats actions a given number of times by using two approaches. Repetitive tasks are easily handled by writing code that includes a loop—either a for or while loop. To write the best loop, remember to include all three conditions: initialization, termination, and the action that takes place for each loop iteration.
(upbeat music) … - [Instructor] For this challenge, … use exercise file 03_09-challenge1 as a base … where the user is prompted for integer input. … Your task is to write a loop … that repeats based on user input. … Each time the loop repeats, … output a single hyphen character. … So if the user types in 50, the program generates 50 hyphens … a line across the text screen. … Use the putchar function to output the hyphen character. … You are to write two solutions to this challenge. … The first solution uses a for loop. … The second solution performs the same task, … but with a while loop. … This challenge should take about 15 minutes to complete. … …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.