+ 1
Explain !! Plss😅
https://code.sololearn.com/cHB2k2JYbTqh/?ref=app input 8 1 3 8 2 9 7 6 5 expect output 1 2 3 5 6 7 8 9 my output 1 2 3 8 9 why!!!!
2 ответов
+ 4
#include <stdio.h>
#define MAX 1000 // <-- This is unused why?
int main() 
{
    int i,n,temp=0,j;
    // Array declaration doesn't belong here
    // because we haven't got value for (n)
    // int a[n];// <-- Wrong place for this...
    scanf("%d",&n);
    // Now that we have a value for (n) we can
    // declare our array here...
    int a[n];// <-- Right place for this...
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(j=0;j<n;j++)
    {
        for(i=0;i<n-1;i++)
        {
             if(a[i]>a[i+1])
             {
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
             }
             else 
                 continue;
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}
Please try to indent your code more accordingly, it improves readability and helps finding problem.
Happy coding ; )
+ 1
thanks alot man!! best community ever!!☺



