33. Diagrama de Flujo en DFD || Ciclos o Bucles || Suma de números pares desde 1 hasta n
New Section
In this section, the speaker introduces a programming problem related to loops and cycles. The task is to create a program that calculates the sum of all even numbers from one to a given number and determines how many even numbers are present.
Problem Introduction
- The video presents problem number 11 involving loops and cycles.
- Users are required to input a number 'n' for the program to calculate the sum of even numbers up to 'n' and determine the count of even numbers.
Variables Initialization and User Input
This part focuses on initializing variables for calculations and obtaining user input for the desired number.
Variable Declaration
- Initialize variables: 'n' for user input, 'sum' set to zero, and 'count' also initialized as zero.
User Input
- Prompt the user to enter a number ('n') which will be stored in the variable 'n'.
Loop Implementation
Implementing a loop structure to iterate through numbers up to 'n'.
Loop Structure
- Utilize a loop structure starting from 1 up to 'n', incrementing by one each time.
Calculating Even Numbers
Determining if a number is even within the loop and performing relevant calculations.
Checking for Even Numbers
- Use conditional statement within the loop: If 'i mod 2 == 0', increment 'sum' by adding current value of 'i'.
Counting Even Numbers
- Increment count by one each time an even number is encountered within the loop.
Output Display
Displaying results including sum of even numbers and total count of even numbers found.
Result Presentation
- Output on screen: Display calculated sum ('sum') of even numbers along with total count ('count') of even numbers found.
Program Testing
Testing program functionality with sample inputs for verification.
Test Cases
- Enter test cases like 10 or 25, verifying correct output showing sum of even numbers and total count.