Thread: How to sort the array from smallest to largest in this code?

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    7

    How to sort the array from smallest to largest in this code?

    Code:
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    double integrate(double lower, double upper);
    
    int main()
    {
    int ranges[][2] = {{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{ 8,9},{9,10}};
    for(int i=0; i<10; ++i)
    cout << integrate(ranges[i][0],ranges[i][1]) << endl;
    return 0;
    }
    
    double integrate(double lower, double upper)
    {
    double n = 0.0;
    double dx = (upper-lower)/2000;
    for (double i = lower; i < upper-dx; i += dx)
    {
    n += sin(i)*dx;
    }
    return n;
    }
    I finished this code, and this is only my problem. How do you make them in ascending order in this code? Thank you.
    Last edited by Salem; 04-14-2010 at 09:56 AM. Reason: RESTORED POST - do not edit your posts to nothing again!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Using your favorite sorting algorithm.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Will you please stop editing your posts and removing what you've posted... please!!!! You're doing this everywhere and it must stop... or I will smite you!
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    smoted
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 07-28-2009, 03:15 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  4. Finding largest element in array
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2005, 09:18 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

Tags for this Thread