Skip to content

C++ Program to Count and Print Even Numbers and Sum of Odd Numbers

C++ Program to Count and Print Even Numbers and Sum of Odd Numbers..
This Code is shared by Akshay Durge


Sample Output:





Code:


//Program to count and print the number of even numbers and sum of odd numbers.
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int limit;
void cal(int);         //prototype void
cout<<“Enter Limit”<<endl;
cin>>limit;
cal(limit);          //calling the function
getch();
return(0);
}
void cal(int x)              //function cal with argument having one variable
{
int ctr=0,sum=0;
for(int i=1;i<=x;i++)
{
if(i%2==0)
{
ctr=ctr+1;
}
else
{
sum=sum+i;
}
}
cout<<“Even numbers=”<<ctr<<endl;
cout<<“Sum of odd numbers=”<<sum;
}

Comment bellow for your Query and Feedback… 🙂 

1 thought on “C++ Program to Count and Print Even Numbers and Sum of Odd Numbers”

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!