ssoni

loops.c

Dec 7th, 2021 (edited)
1,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. void countdown(int max);
  5.  
  6. int main(void)
  7. {
  8.     int i;
  9.  
  10.     for (i=0; i<=4; i++)
  11.     {
  12.         printf("Hello %i\n", i+1);
  13.     }
  14.  
  15.     int total=0;
  16.     int j=1;
  17.  
  18.     while (j<=100)
  19.     {
  20.         total = total + j;
  21.         j++;
  22.     }
  23.     printf("1+2+3...+99+100 = %i\n", total);
  24.  
  25.     countdown(10);
  26.  
  27. }
  28.  
  29. void countdown(int max)
  30. {
  31.     for (int i=max; i>0; i--)
  32.     {
  33.         printf("%i ", i);
  34.     }
  35.     printf(" ...blast off!\n");
  36. }
  37.  
  38.  
  39.  
Add Comment
Please, Sign In to add comment