473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to sort entered integer into ascending & find the average ?

80
Here is my source code....
And any one pls help me how can we find the output integers sort by ascending and find there average...

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main() {
  4.    int num[10];
  5.    clrscr();
  6.    cout<<"ENTER NUMBERS TO SORT THEM IN ASCENDING ORDER & FIND THE AVERAGE"<<endl;
  7.    for(int times=0;times<=10;times++)
  8.    {
  9.       cout<<"Enter a number";
  10.       cin>>num[times];
  11.    }
  12.    for(int z=0;z<=10;z++)
  13.    {
  14.       cout<<"Ouput is : "<<num[z]<<endl;
  15.    }
  16.    getch();
  17. }
Feb 2 '07 #1
6 3692
horace1
1,510 Expert 1GB
have a look at
http://en.wikipedia.org/wiki/Sorting_algorithm
for sort algorithms
Feb 2 '07 #2
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main() {
  4.    int num[10];
  5.    clrscr();
  6.    cout<<"ENTER NUMBERS TO SORT THEM IN ASCENDING ORDER & FIND THE AVERAGE"<<endl;
  7.    for(int times=0;times<=10;times++)
  8.    {
  9.       cout<<"Enter a number";
  10.       cin>>num[times];
  11.    }
  12.    for(int z=0;z<=10;z++)
  13.    {
  14.       cout<<"Ouput is : "<<num[z]<<endl;
  15.    }
  16.    getch();
  17. }
There's one problem with your code. You start times and z at 0 to access elements of your array, but your end condition is <= 10 - you will try to access num[10] twice, which is out of bounds of the array.

How do you find the average of any set of numbers? You add them all together, then divide that total by the number of elements. Repeat this with your array, making sure to cast the element number to a double before dividing.

There are plenty of sorting algorithms out there, or you can make your own - since you have the numbers being entered one by one, every time a number is entered you can look for the proper place for that number to go.
Feb 2 '07 #3
reon
80
I only know conio,iostream & fstream..is there any probability to complete the program in that way....
Feb 2 '07 #4
Ganon11
3,652 Expert 2GB
Yes - in fact, for the actual sorting, you won't need any of these libraries. iostream will be handy for seeing what you're doing, though.
Feb 2 '07 #5
reon
80
then pls help me out how can i complete this program and get output in ascending orders and find the average...
Feb 2 '07 #6
Ganon11
3,652 Expert 2GB
I have already told you how to get the average - look up and read my first post. In fact, I also told you an easy method of sorting the numbers. Now it's your turn to try the methods I've outlined and see what problems you are having.
Feb 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ken R. | last post by:
Hello all, I am relatively new to python but I am having an issue with custom sort functions.. I am trying to sort a list of lists or tuples with arbitrary ascending or descending sorts. For...
1
by: Aravind | last post by:
Hi folks. My form, frmHistory, has a combo box, cboName, that filters frmHistory by member's name (using a macro). frmHistory also has a few labels that I use for sorting the form (using VBA...
2
by: Deano | last post by:
If I sort my table on a date in ascending order then empty dates are listed first; SELECT tblReview.ID, tblReview.ReviewDate, tblReview.NextReview FROM tblReview ORDER BY tblReview.NextReview; ...
2
by: Steve Chatham | last post by:
How do you make a sort work in ascending & descending order on the column in a datagrid. I have it now where it'll return the numbers from lowest to highest. SC
1
by: Jason P Opdycke [MSFT] | last post by:
Hello All - I have 2 list boxes. Items in Left list box populated from a DB. I remove an item from the left box and add an item to the right box to allow user selection. When that item is...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
1
by: vb newbie | last post by:
Does anybody have suggestions on how to programatically sort a ListView on TWO subitem columns? Here's the code I'm using to sort on one subitem: Public Function Compare(ByVal x As Object, ByVal...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following function to get the data from mysql database. i have entered appnum field as text filed in the database which has leading zeroes to this field like if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.