write a program to input a 5 integers array . calculate and print the sum of all even numbers stored in the array. eg. input -4,7,1,3,6 output -sum=10
CyberAkay:
atleast you could thank me for answering your question
Answers
Answered by
2
Dear user,
Kindly mark the answer as brainliest if you find it useful.
Here's what you were looking for:
#include <iostream>
#include <iomanip>
int main()
{
int n = 0;
int j = 0;
int sum = 0;
char again = 'Y';
sum = 0; j = 2;
while (again=='y' || again=='Y')
{
cout << "Enter a number: " ;
cin >> n;
sum=0;
for(j=2;j<=n; j+=2)
{
sum += j;
}
cout << "the sum of even numbers from 1 to " << n << " is " << sum << endl;
cout << "Do you want to do this again (Y/N)?"; cin >> again;
}
return 0;
}
Kindly mark the answer as brainliest if you find it useful.
Here's what you were looking for:
#include <iostream>
#include <iomanip>
int main()
{
int n = 0;
int j = 0;
int sum = 0;
char again = 'Y';
sum = 0; j = 2;
while (again=='y' || again=='Y')
{
cout << "Enter a number: " ;
cin >> n;
sum=0;
for(j=2;j<=n; j+=2)
{
sum += j;
}
cout << "the sum of even numbers from 1 to " << n << " is " << sum << endl;
cout << "Do you want to do this again (Y/N)?"; cin >> again;
}
return 0;
}
Similar questions