Skip to content
Snippets Groups Projects
Commit 1df27ae5 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele für "break", 18.10.2021

parent 68472d0e
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
int main (void)
{
int a = 0;
int b = 1;
printf ("%d\n", b);
for (int i = 0; i < 10; i++)
{
int c = a + b;
a = b;
b = c;
printf ("%d\n", b);
}
return 0;
}
#include <stdio.h>
/* Aufgabe: Finde die erste Fibonacci-Zahl, die größer ist als 10. */
int main (void)
{
int a = 0;
int b = 1;
while (1)
{
int c = a + b;
a = b;
b = c;
if (b > 10)
{
printf ("Die erste Fibonacci-Zahl, die größer ist als 10, lautet: %d\n", b);
/* Dieses printf() erfolgt von der Logik her nach der Schleife,
es steht aber im Quelltext _innerhalb_ der Schleife. */
break;
}
}
return 0;
}
#include <stdio.h>
/* Aufgabe: Finde die erste Fibonacci-Zahl, die größer ist als 10. */
int main (void)
{
int a = 0;
int b = 1;
while (b <= 10)
{
int c = a + b;
a = b;
b = c;
}
printf ("Die erste Fibonacci-Zahl, die größer ist als 10, lautet: %d\n", b); /* nach der Schleife */
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment