C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 2nd, 2012, 06:08 AM
Fromar123 Fromar123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Fromar123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m
Reputation Power: 0
HELP 2d array sort rows by its sum value

Hi, i'd like to ask for some help about a problem i got... So i got this code right now:
Code:
    const int rows = 5;
    const int cols = 3;
    int tocke = 0;
    
    int tekmovalci[rows][cols]={{7, 6, 9},
                                {8, 7, 8},
                                {6, 9, 10},
                                {7, 7, 9},
                                {8, 8, 10}};
                                    
    for(int r=0; r<rows; r++){
            cout << r+1 << ". ";
            for(int c=0; c<cols; c++){
                    cout << tekmovalci[r][c] << " ";
                    tocke += tekmovalci[r][c];        
            }
            cout << tocke << endl;
            tocke = 0;       
    }


and the 'int tocke' represents the sum of all numbers in a row, and now i'd like to sort the output by the value of sum.

this is the current output:
1. 7 6 9 22
2. 8 7 8 23
3. 6 9 10 25
4. 7 7 9 23
5. 8 8 10 26

and i want it like this:
5. 8 8 10 26
3. 6 9 10 25
2. 8 7 8 23
4. 7 7 9 23
1. 7 6 9 22

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > HELP 2d array sort rows by its sum value


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap