0
What's the error in ascending order program
#include<stdio.h> #include<conio.h> void main() { int a[100],i,j,n,k,b,l; printf("enter the no of elements"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the %d element",i+1); scanf("%d",&a[i]); } for(k=0;k>n;k++) { for(j=k+1;j<n;j++) { if(a[k]>a[j]) { b=a[k]; a[k]=a[j]; a[j]=b; } } } for(l=0;l<n;l++) printf("%d\n",a[l]); getch(); }
7 Antworten
+ 1
On quick glance: "k>n" is probably incorrect.
Also, void main should really be int main even if some compilers accept the former.
+ 1
Thanks Dennis sir...your guess is correct...I got the right answer
0
...
0
Logic is correct but if loop cannot work... The input value is equal to output...for eg if we give the input. 4,6,7,3,2 the output is also same..
0
Yes, you're using the wrong compare operator, is what I was trying to hint at.
0
What's the compare operate..pls explain clearly ...in which part I did a mistake
0
"for(k=0;k>n;k++)" the '>' is incorrect.
Currently you're only entering the loop if k is bigger than n which will ( almost ) never be true.
You have to check if k is smaller than n.
Surely you know which operator to use, you used it in the same program.