Sorting An Array

Accept 10 numbers and store in an array, print sorted array in descending and ascending order:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,temp;
clrscr();
printf("Enter 10 nos\n");



for(i=0;i<10;i++) 

 scanf("%d",&a[i]);
 for(i=0;i<10;i++)
 { 
 for(j=i+1;j<10;j++)
 {
 if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<10;i++)

 printf(" %d ",a[i]);
 printf(" Nos sorted in ascending order\n");
 printf("\n");
 for(i=9;i>=0;i--)
printf(" %d ",a[i]);
printf(" Nos sorted in descending order\n");
getch();
}

21 comments:

  1. Hi, Nice Program for Sorting An Array.Thanks, its really helped me......

    -Aparna
    Theosoft

    ReplyDelete
  2. MERGE SORT, BUBBLE SORT, HEAP SORT, INSERTION SORT, QUICK SORT and other types of sorting at :

    http://thec-language.blogspot.in/p/blog-page_23.html

    ReplyDelete
  3. Best C Programs with Complete Explanation ..
    Visit To Code ►► Lightning Code

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. C tutorial with free and simple example on Data Types & Variables, Conditionals, Loops, Arrays & Strings etc. Here you can download simple and easy online c tutorial for beginners .C Programming online test.

    ReplyDelete
  6. Good
    Here is a link for C/C++ programs and pointer programs. This may be useful for you.

    C Programs

    C++ Programs

    ReplyDelete
  7. Go on cproinfo.blogspot.com
    For all programs,interview questions and examples

    ReplyDelete
  8. To know the programming technique: "Make Your Program Trial Version in C" visit:
    udebayan.blogspot.com

    ReplyDelete
  9. To know the programming technique: "Make Your Program Trial Version in C" visit:
    udebayan.blogspot.com

    ReplyDelete
  10. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete

  11. This blog is awesome,thanks for ur valuable inforamtion ,u want more inforamtion about C programming languages join C programming classes in bangalore,visit : Aptech computer education,my tage are :

    C training bangalore,C courses bangalore,C classes bangalore,C institute bangalore,C coaching centers bangalore,C programming institute in bangalore,C programming classes in bangalore

    ReplyDelete
  12. thanks for creating a nice post on c programming but did you know what is loop in c programming

    ReplyDelete
  13. Really a great post, i really impressed with your blog, thanks for sharing!!
    DevOps Online Training

    ReplyDelete
  14. Write a C program to print all prime number between 1 to 300 using for loop.

    Code of given problem:

    int main()
    {
    int a,b;
    printf("List of prime numbers between 1 to 300:\n");
    printf("%d\t",a=2);
    for(a=1;a<=300;a++)
    {
    for(b=2;b<=a-1;b++)
    if(a%b==0)
    break;
    else if(b==a-1)
    {
    printf("%d\t",a);
    }
    }
    return 0;
    }

    Very informative blog!
    Please take some time to visit my blog @
    Top 10 programming examples in C

    Thanks!

    ReplyDelete

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number