View Single Post
Old May 2nd, 2008, 2:23 AM   #1
LAYAN-2008
Newbie
 
Join Date: Apr 2008
Posts: 3
Rep Power: 0 LAYAN-2008 is on a distinguished road
find out the average of odd numbers -do-while statement.

hi , I want to know if my answer is true??and I want your opinion in my answer..
• Write a program fragment to find out the average of odd numbers between two numbers given by the user using a do-while statement?


int sum=0;
int X=50;
int Y = 70;
int count=0;
do{
X++;
if(X%2!=0)
{
sum +=X;
count++;
}
}
while(X<Y);
int average = sum/count;
System.out.println("average=" + average );
LAYAN-2008 is offline   Reply With Quote