fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int i, j, n, temp;
  6. int a[10];
  7.  
  8. printf("Enter the size of the array: ");
  9. scanf("%d", &n);
  10.  
  11.  
  12.  
  13. printf("Enter the elements of the array: ");
  14. for (i = 0; i < n; i++)
  15. {
  16. scanf("%d", &a[i]);
  17. }
  18.  
  19.  
  20. for (i = 0; i < n - 1; i++)
  21. {
  22. for (j = 0; j < n - 1 - i; j++)
  23. {
  24. if (a[j] > a[j + 1])
  25. {
  26.  
  27. temp = a[j];
  28. a[j] = a[j + 1];
  29. a[j + 1] = temp;
  30. }
  31. }
  32. }
  33.  
  34. printf("The elements of the sorted array are: ");
  35. for (i = 0; i < n; i++) {
  36. printf("%d ", a[i]);
  37. }
  38. printf("\n");
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.03s 25616KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main() 
{
    int i, j, n, temp;
    int a[10]; 

    printf("Enter the size of the array: ");
    scanf("%d", &n);

    

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

    
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - 1 - i; j++) 
        { 
            if (a[j] > a[j + 1])
            {
                
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }

    printf("The elements of the sorted array are: ");
    for (i = 0; i < n; i++) {
        printf("%d ", a[i]); 
    }
    printf("\n"); 

    return 0;
}