Explain !! PlssšŸ˜… | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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!!!!

19th Apr 2018, 8:10 AM
hoang vu
hoang vu - avatar
2 Respostas
+ 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 ; )
19th Apr 2018, 10:34 AM
Ipang
+ 1
thanks alot man!! best community ever!!ā˜ŗ
19th Apr 2018, 11:34 AM
hoang vu
hoang vu - avatar