What is an example of iteration in C?
Question
What is an example of iteration in C?
🧐 Not the exact question you are looking for?Go ask a question
Solution
Iteration in C can be achieved using loop structures such as for, while, and do-while. Here is an example using a for loop:
#include <stdio.h>
int main() {
int i;
for(i = 0; i < 5; i++) {
printf("%d\n", i);
}
return 0;
}
In this example, the for loop will iterate 5 times. The variable i is initialized to 0, and the condition i < 5 is checked before each iteration. If the condition is true, the loop body is executed and i is incremented by 1 (i++). The loop continues until i is no longer less than 5.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.