Wednesday, 27 July 2011


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... :) 

Related Posts :



1 comment:

  1. print spelling of entered integer eg.if 57 print five seven

    ReplyDelete