Skip to main content

✍️ Practice (For)

1. Sum of Evens​

Ask the user for a limit, then add up every even number from 2 to that limit.

2. Charge your Phone​

A phone starts at 100% battery and loses 20% each hour:

int batteryLevel = 100;

for (int hour = 0; hour < 4; hour++)
{
batteryLevel -= 20;
}

Console.WriteLine($"Battery left: {batteryLevel}%");

Fill in a trace table showing hour and batteryLevel for each pass, then predict what the program prints.

hourhour < 4batteryLevel after the pass

3. Limit Sum​

Loop through a range of numbers from 1 to 100. Keep a running total sum of these numbers. As soon as the total sum exceeds 50, stop the loop and print the total sum and the last number added.

4. Clock​

Display every minute of every hour in a day.

0:00
0:01
0:02
…
23:58
23:59

5. Triangle​

Write a program to display a cute right angle triangle as shown below:

*
**
***
****