0
Can anyone help: I want a iterative and without function c program for verifying if a vector is sorted increasily or not?
int main(){ int t[]={1,0,7,6}; int croiss=1; int i=0; while((i<4)&&(croiss==1)){ if(t[i]>t[i+1]) croiss=0; else i++; } if(croiss<=0) printf("not increased"); else printf("increased"); return 0; }
4 odpowiedzi
+ 3
Sure, that would work, though in a classical boolean sense, only 0 is considered false, thus == might be a little more accurate, but it doesn't matter in your case, since you only ever use 0 and 1.
+ 1
In your if statement at the end, you used the assignment operator instead of the comparison operator, therefore it will always print "increased". Other than that, I don't see anything wrong with it.
0
So i'll edit into croiss<=0 right?
0
Thank you Shadow