Write down the program to sort the array.

Answer Posted / anon

#include <stdio.h>

int main() {
int i, j, size, values[100], temp;

printf("Enter the size of an array: ");
scanf("%d",&size);
printf("Enter the values of array: ");
for(i=0;i<size;i++){
scanf("%d",&values[i]);
}

for(i=0;i<size-1;i++){
for(j=i+1;j<size;j++){
if(values[i]<values[j]){
temp=values[i];
values[i]=values[j];
values[j]=temp;
}
}
}
printf("Sorted array:
");
for(i=0;i<size;i++){
printf("%d ",values[i]);
}

return 0;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I read and write comma-delimited text?

844


What is the difference between #include and #include 'file' ?

821


What are the different types of endless loops?

837


What is the significance of scope resolution operator?

1126


Explain the properties of union.

826


what is the difference between class and unio?

2108


What is abstract data structure in c?

766


PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE

1706


The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

993


What are multibyte characters?

853


Which is better pointer or array?

802


Explain how can I prevent another program from modifying part of a file that I am modifying?

866


What is non linear data structure in c?

777


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1695


Explain data types & how many data types supported by c?

821