Click here to Skip to main content
15,851,453 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Activex Control Pin
RichardK15123-Oct-17 0:49
RichardK15123-Oct-17 0:49 
GeneralRe: MFC Activex Control Pin
leon de boer25-Oct-17 10:18
leon de boer25-Oct-17 10:18 
QuestionTo arrange n numbers in descending order ? Pin
Tarun Jha13-Oct-17 10:02
Tarun Jha13-Oct-17 10:02 
AnswerRe: To arrange n numbers in descending order ? Pin
jeron113-Oct-17 10:08
jeron113-Oct-17 10:08 
QuestionRe: To arrange n numbers in descending order ? Pin
David Crow13-Oct-17 17:06
David Crow13-Oct-17 17:06 
AnswerRe: To arrange n numbers in descending order ? Pin
Richard MacCutchan13-Oct-17 23:44
mveRichard MacCutchan13-Oct-17 23:44 
AnswerRe: To arrange n numbers in descending order ? Pin
«_Superman_»15-Oct-17 19:02
professional«_Superman_»15-Oct-17 19:02 
AnswerRe: To arrange n numbers in descending order ? Pin
CPallini16-Oct-17 4:21
mveCPallini16-Oct-17 4:21 
C
#include <stdio.h>

#define  N 50

int main()
{
  int num[N], i=0,  count =0;

  printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");

  do
  {
    if( scanf("%d", &num[i]) != 1) break;
    ++i;
    count++;

  } while ( i<N && num[i-1] !=0 );



  int k = 0;
  while(k < count-1)
  {
    int largest_index = k;

    for(i=k+1; i<count; ++i)
    {

      if( num[largest_index] < num[i] )
        largest_index = i;
    }
    int tmp = num[k];
    num[k] = num[largest_index];
    num[largest_index] = tmp;
    ++k;
  }

  for (i=0; i<count; ++i)
    printf("%d\n", num[i]);


  return 0;
}


As an alternative, tou might use qsort:
C
#include <stdio.h>
#include <stdlib.h>

#define  N 50

int comp(const void * a, const void *b)
{
  return *(int *)b - *(int*)a;
}

int main()
{
  int num[N], i=0,  count =0;

  printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");

  do
  {
    if( scanf("%d", &num[i]) != 1) break;
    ++i;
    count++;

  } while ( i<N && num[i-1] !=0 );


  qsort(num, count, sizeof(num[0]), comp);

  for (i=0; i<count; ++i)
    printf("%d\n", num[i]);

  return 0;
}


modified 16-Oct-17 9:37am.

QuestionTo find biggest of n numbers ? Pin
Tarun Jha13-Oct-17 6:44
Tarun Jha13-Oct-17 6:44 
AnswerRe: To find biggest of n numbers ? Pin
jschell13-Oct-17 6:56
jschell13-Oct-17 6:56 
GeneralRe: To find biggest of n numbers ? Pin
Tarun Jha13-Oct-17 7:02
Tarun Jha13-Oct-17 7:02 
GeneralRe: To find biggest of n numbers ? Pin
jschell15-Oct-17 8:11
jschell15-Oct-17 8:11 
AnswerRe: To find biggest of n numbers ? Pin
Richard MacCutchan13-Oct-17 7:16
mveRichard MacCutchan13-Oct-17 7:16 
GeneralRe: To find biggest of n numbers ? Pin
Tarun Jha13-Oct-17 7:22
Tarun Jha13-Oct-17 7:22 
GeneralRe: To find biggest of n numbers ? Pin
jeron113-Oct-17 7:34
jeron113-Oct-17 7:34 
GeneralRe: To find biggest of n numbers ? Pin
Richard MacCutchan13-Oct-17 7:51
mveRichard MacCutchan13-Oct-17 7:51 
GeneralRe: To find biggest of n numbers ? Pin
Tarun Jha13-Oct-17 8:14
Tarun Jha13-Oct-17 8:14 
GeneralRe: To find biggest of n numbers ? Pin
David Crow13-Oct-17 17:10
David Crow13-Oct-17 17:10 
GeneralRe: To find biggest of n numbers ? Pin
Richard MacCutchan13-Oct-17 23:33
mveRichard MacCutchan13-Oct-17 23:33 
AnswerRe: To find biggest of n numbers ? Pin
leon de boer13-Oct-17 7:50
leon de boer13-Oct-17 7:50 
Questionwhile error ? Pin
bluatigro12-Oct-17 1:23
bluatigro12-Oct-17 1:23 
QuestionRe: while error ? Pin
David Crow12-Oct-17 3:35
David Crow12-Oct-17 3:35 
AnswerRe: while error ? Pin
Manish K. Agarwal12-Oct-17 5:22
Manish K. Agarwal12-Oct-17 5:22 
AnswerRe: while error ? Pin
Manish K. Agarwal12-Oct-17 5:26
Manish K. Agarwal12-Oct-17 5:26 
QuestionWhere is GetTickCount64()? Pin
inlandchris11-Oct-17 12:10
inlandchris11-Oct-17 12:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.