C program to calculate the sum of odd and even numbers
belongs to collection: C programs - Basic C Programs
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
belongs to collection: C programs - Basic C Programs
total answers (1)
C program to calculate the sum of odd and even numbers - Source code
Program Output
Program Explanation
1. Two integer variables i and n are declared. Two integer variables sum_odd and sum_even are declared and initialized to 0.
2. For loop starts the first iteration with 1 and continue up to the number entered by the user (n).
3. To check whether the number in the current iteration is even or odd, modulus operator (%) is used. This operator divides the number by 2 and returns the remainder. If reminder returned is 0, the number is even otherwise it is odd.
4. The value of sum_even and sum_odd operators is updated inside the loop and printed when the loop ends.
need an explanation for this answer? contact us directly to get an explanation for this answer