write a c++ program that accepts a list of integers as input and print the sum of even integers
Answers
Answered by
3
Answer:
// C++ program to print all Even
// and Odd numbers from 1 to N
#include <bits/stdc++.h>
using namespace std;
// Function to print even numbers
void printEvenNumbers(int N)
{
cout << "Even: ";
for (int i = 1; i <= 2 * N; i++) {
// Numbers that are divisible by 2
if (i % 2 == 0)
cout << i << " ";
}
}
// Function to print odd numbers
void printOddNumbers(int N)
{
cout << "\nOdd: ";
for (int i = 1; i <= 2 * N; i++) {
// Numbers that are not divisible by 2
if (i % 2 != 0)
cout << i << " ";
}
}
// Driver code
int main()
{
int N = 5;
printEvenNumbers(N);
printOddNumbers(N);
return 0;
Similar questions
Science,
2 months ago
Science,
2 months ago
Computer Science,
2 months ago
Math,
10 months ago
Math,
10 months ago