Counting Even Numbers with a For Loop in C
📖 Scenario: You have a list of numbers representing daily sales counts in a small shop. You want to find out how many days had an even number of sales.
🎯 Goal: Build a C program that counts how many numbers in a given list are even using a for loop.
📋 What You'll Learn
Create an integer array called
sales with the exact values: 12, 7, 9, 20, 15Create an integer variable called
count_even and set it to 0Use a
for loop with an integer variable i to iterate over the sales arrayInside the loop, use an
if statement to check if the current number is evenIncrease
count_even by 1 for each even number foundPrint the final value of
count_even using printf💡 Why This Matters
🌍 Real World
Counting specific types of data in a list is common in many real-world tasks, like analyzing sales, temperatures, or survey results.
💼 Career
Understanding loops and conditions is essential for programming jobs, as they help automate repetitive tasks and data analysis.
Progress0 / 4 steps