Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære For Loop Practice | Control Statements
C Basics

book
For Loop Practice

Example from the Previous Lesson

main.c

main.c

copy
#include <stdio.h>

int main()
{
int array[] = { 3, 6, 2, 134, 45,
2, 564, 8, 3, 531 };

for (int i = 0; i < 10; i++)
{
printf("Index of element: %d\tValue of element: %d\n", i, array[i]);
}

return 0;
}
1234567891011121314
#include <stdio.h> int main() { int array[] = { 3, 6, 2, 134, 45, 2, 564, 8, 3, 531 }; for (int i = 0; i < 10; i++) { printf("Index of element: %d\tValue of element: %d\n", i, array[i]); } return 0; }
Opgave

Swipe to start coding

Use the for loop to display numbers from 10 down to 0 on the screen.

Løsning

#include <stdio.h>

int main()
{
for (int i = 10; i >= 0; i--)
{
printf("%d\n", i);
}

return 0;
}

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 7
single

single

#include <stdio.h>

int main()
{
for (int i = 10;___;___)
{
printf("%d\n", i);
}

return 0;
}

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt