Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
code to add numbers in an array truBlu1 Java 9 Oct 12th, 2007 10:08 PM
random Numbers in openGL csrocker101 C++ 5 Apr 24th, 2007 8:02 PM
Vector problem - find max, min and positions codylee270 C++ 12 Mar 20th, 2006 12:57 AM
Random Number & Average Problem Hadrurus Java 6 Aug 15th, 2005 1:08 PM
Program that can find a patern Anyways C++ 2 Mar 22nd, 2005 2:27 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC