Write a program in C++ to accept 15 integer numbers then calculate and
display count and sum of odd & even numbers out of 15 given numbers.
Answers
Answered by
1
Answer:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i, num; //declare variables i, num
int oddSum=0,evenSum=0;
//declare and initialize variables oddSum,evenSum
cout<<"Enter the value of num \n";
cin>>num;
for(i=1; i<=num; i++){// for loop use to iterate 1 to num
if(i%2==0) //Check even number for sum
evenSum=evenSum+i;
else
oddSum=oddSum+i;
}
cout<<"Sum of all odd numbers are:"<< oddSum;
cout<<"\nSum of all even numbers are:"<<evenSum;
getch();
return 0;
}
Similar questions