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.  

 

Comments

Post a Comment

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

Popular posts from this blog

Unacceptable Individual Drives Twitter

ChatGPT on smartwatches

Program to find greatest number among any three different numbers inputted by User.