Pages

Thursday, 16 February 2017

Even Odd Calculation

Q : Write a program to sum all even and odd number from 1 to given number ?

Solution : 


class sumevenodd
{
void get_sum(int n)
{
int i,esum=0,osum=0;
for(i=1;i<=n;i++)
{
if(i%2==0)
esumt=esum+i;
else
osum=osum+i
}
System.out.println("Sum even number is " + esum );
System.out.println("Sum odd number is " + osum );
}

}

No comments:

Post a Comment