I used the while loop and when I looked on the forum, I noticed almost everyone using the for loop.
I found this to be more ‘modular’, meaning if I wanted to add a user input, it would be easy to set the starting number, at least that is what my initial thought process was at the time.
#include <stdio.h>
int main(int argc, const char * argv[]) {
/* Chapter 8 Challenge: Counting Down.
Write a program that counts backward from 99 to 0 by 3, printing each number.
If the number is divisible by 5, it should also print the words "Found one!".
Thus the output should look like: 99, 96, 93, 90 Found one! 87, etc to 0 Found one! */
//First, setting i to be the starting number of 99.
int i = 99;
//Using a while loop to countdown to zero and printing the number.
while (i >= 0) {
printf("%d\n", i);
//Then looking to see if it is divisible by 5, if yes then printing "Found one!"
if (i % 5 == 0) {
printf("Found one!\n");
}
//Then, subtract 3 from i and roll the loop.
i -= 3;
}
return 0;
}