Advertisement
informaticage

While vs Do-While example

Feb 9th, 2022
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.   // Leggere e validare un input
  5.   // Condizione input < 5
  6.  
  7.   // While loop solution
  8.   int n;
  9.   printf("N: ");
  10.   scanf("%d", &n);
  11.  
  12.   while (n < 5) {
  13.     printf("N: ");
  14.     scanf("%d", &n);
  15.   }
  16.   printf("Numero inserito: %d\n", n);
  17.  
  18.   // Do while loop solution
  19.   int n;
  20.   do {
  21.     printf("N: ");
  22.     scanf("%d", &n);
  23.   } while (n < 5);
  24.   printf("Numero inserito: %d\n", n);
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement