Advertisement
Mizuhara_Chizuru

Untitled

Jun 25th, 2021
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Code by Surya a.k.a Sunny*/
  2. /* by https://www.codechef.com/users/spsc */
  3. #include <bits/stdc++.h>
  4. #define lli long long
  5. #define pi 3.14159265358979323846
  6. #define MOD 1000000007
  7. #define foi(n)  for(lli i=0;i<n;i++)
  8. #define foj(n)  for(lli j=0;j<n;j++)
  9. #define test(T) lli T;cin>>T;while(T--)
  10. #define loop(i, a, b) for(int i = (a); i<= (b); i++)
  11. using namespace std;
  12. int main()
  13. {
  14.   ios_base::sync_with_stdio(false);
  15.  
  16.    int n;
  17.    printf("Size of array? ");
  18.    scanf("%d",&n);
  19.    int A[n],temp;
  20.    foi(n)
  21.     scanf("%d",&A[i]);
  22.    for(int i=1;i<n;i++)
  23.    {
  24.      for(int j=i;j>0;j--)
  25.      {
  26.        if(A[j]<A[j-1])
  27.        {
  28.          temp=A[j];
  29.          A[j]=A[j-1];
  30.          A[j-1]=temp;
  31.          //A[j+1]=A[j];
  32.        }
  33.        //A[j+1]=temp;
  34.      }
  35.    }
  36.    printf("\nSorted array is : \n");
  37.    foi(n)
  38.     printf("%d , ",A[i]);
  39.  }
  40.  
Advertisement
RAW Paste Data Copied
Advertisement