Create a program that prints all even numbers from 1 to 50 inclusive. (You must use a loop.)
Create a program that prints the first 33 multiples of 3. (3, 6, 9, 12, …, 99)
Create a program that prints all numbers between 1 and 100 inclusive, except for numbers evenly divisible by 5.
Create a program that prints all multiples of 8 between 8 and 160 inclusive, except for numbers evenly divisible by 3. (8, 16, 32, 40, 56, …)
How many times will the following loop run? (Hint: Don’t try to run it)
void the_coolest_loop(void)
{
int i;
for (i = 0; i < 10; i--)
{
("i is %d!\n", i);
printf}
}
void print_sums(void)
{
int sum;
for (int j = 0; j != 10; j++)
{
sum = sum + j;
}
printf("Sum is %d\n", sum);
printf("Resetting...\n");
sum = 0;
for (int j = 0; j != 10; j++)
{
sum = sum + j;
}
printf("Sum is now %d\n", sum);
}
int number = 5;
while (number < 500)
{
("number = %d\n", number);
printf++;
number}
int items;
int item_cost = 5;
int remaining_dollars = 50;
("You have $%d. Let's see how many items you can buy!\n", remaining_dollars);
printf
for (items = 0; remaining_dollars >= item_cost; items++)
{
-= item_cost;
remaining_dollars }
("You bought a total of %d items with your money!\n", items); printf
int x;
// Loop 1
= 0;
x while (x < 10)
{
("%d\n", x);
printf++;
x}
// Loop 2
= 0;
x do
{
("%d\n", x);
printf++;
x} while (x < 10);
sum > 200
.int sum = 0;
for (int i = 0; i < n; i++)
{
if (_____)
{
;
_____}
+= i;
sum }
#include <stdio.h>
int main(void)
{
("We are starting the loop!\n");
printf
for (int i = 0; i < 5; i++)
{
if (i == 3)
{
return 0;
}
("i = %d\n", i);
printf}
("We are ending the loop!\n");
printf
return 0;
}
loopy_loop()
if executed?int loopy_loop(void)
{
int x = 0;
while (x < 10)
{
("x = %d\n", x);
printf
if (x == 5)
{
return 2;
}
+= 2;
x }
return 5;
}
5
10
4
-9
0
The sum is: 10
n
by n
“addition table.” An addition table is like a multiplication table,
except the row and column numbers are added instead of being multiplied.
For example, the following is a 5x5 addition table.0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
n
. Assume that n
is
greater than 2 and is odd. As an example, the following is a diamond
with a height of 5. #
# #
# #
# #
#