This C++ program prompts the user to enter an ending value and then displays all the even and odd numbers up to that value, along with their counts. Here's how the program works:
#include<iostream> using namespace std; int main() { int i,n,even=0,odd=0; cout<<"\nEnter the Ending value:"; cin>>n; cout<<"\nEven numbers:"; for(i=0;i<=n;i++) { if(i%2==0) { cout<<"\n"<<i; even++; } } cout<<"\nOdd numbers:"; for(i=1;i<=n;i++) { if(i%2==1) { cout<<"\n"<<i; odd++; } } cout<<"\nTotal even numbers:"<<even; cout<<"\nTotal odd numbers:"<<odd; return 0; }To download raw file Click Here
Enter the Ending value:10 Even numbers: 0 2 4 6 8 10 Odd numbers: 1 3 5 7 9 Total even numbers:6 Total odd numbers:5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions