Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //Bsp für eine goto-Anweisung
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7. int n;
  8.  
  9. start:
  10.  
  11. puts("Geben Sie eine Zahl zwischen 0 und 10 ein: ");
  12. scanf_s("%d", &n);
  13.  
  14. if(n < 0 || n > 10)
  15. goto start;
  16. else if(n==0)
  17. goto location0;
  18. else if(n==1)
  19. goto location1;
  20. else if(n==2)
  21. goto location2;
  22. else
  23. goto location3;
  24.  
  25. location0:
  26. puts("Ihre Eingabe lautete 0.\n");
  27. goto ende;
  28.  
  29. location1:
  30. puts("Ihre Eingabe lautete 1.\n");
  31. goto ende;
  32.  
  33. location2:
  34. puts("Ihre Eingabe lautete 2.\n");
  35. goto ende;
  36.  
  37. location3:
  38. puts("Sie haben einen wert zwischen 3 und 10 eingegeben.\n");
  39.  
  40. ende:
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement