Ticker

6/recent/ticker-posts

What is an example of iteration in C?


What is an example of iteration in C?



An example of iteration in C is using a loop construct, such as a

for loop

while loop

do-while loop

repeatedly execute a block of code until a certain condition is met.

here an example :-

#include <stdio.h>

int main() {

// Define an array of integers

int numbers[] = {1, 2, 3, 4, 5};

// Iterate over the array using a for loop

printf("Using for loop:\n");

for (int i = 0; i < 5; i++) {

printf("%d\n", numbers[i]); // Print each element

}

return 0;

}

output:-

Using for loop:

1

2

3

4

5

కామెంట్‌ను పోస్ట్ చేయండి

0 కామెంట్‌లు