Technology has advanced to the point where programming has become an essential part of our lives. We use software and applications for communication, entertainment, education, and work, and these are all built on programming languages.

What is Array in C? Write a program to sort numbers in descending order.

 

  • An array is a collection of data items, all of the same type, accessed using a common name.
  • A one-dimensional array is like a list;  A two dimensional array is like a table;  The C language places no limits on the number of dimensions in an array, though specific implementations may.
  1.     #include <stdio.h>
  2.     void main ()
  3.     {
  4.  
  5.         int number[30];
  6.  
  7.         int i, j, a, n;
  8.         printf("Enter the value of N\n");
  9.         scanf("%d", &n);
  10.  
  11.         printf("Enter the numbers \n");
  12.         for (i = 0; i < n; ++i)
  13. 	        scanf("%d", &number[i]);
  14.  
  15.         /*  sorting begins ... */
  16.  
  17.         for (i = 0; i < n; ++i) 
  18.         {
  19.             for (j = i + 1; j < n; ++j) 
  20.             {
  21.                 if (number[i] < number[j]) 
  22.                 {
  23.                     a = number[i];
  24.                     number[i] = number[j];
  25.                     number[j] = a;
  26.                 }
  27.             }
  28.         }
  29.  

 

Share:

1 comment:

If you have any doubt, let me know...

Translate

Wikipedia

Search results