Can anyone help: I want a iterative and without function c program for verifying if a vector is sorted increasily or not? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

13th Feb 2021, 10:30 PM
Coderalgeria
Coderalgeria - avatar
4 Answers
+ 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.
14th Feb 2021, 8:29 AM
Shadow
Shadow - avatar
+ 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.
14th Feb 2021, 8:20 AM
Shadow
Shadow - avatar
0
So i'll edit into croiss<=0 right?
14th Feb 2021, 8:26 AM
Coderalgeria
Coderalgeria - avatar
0
Thank you Shadow
14th Feb 2021, 8:31 AM
Coderalgeria
Coderalgeria - avatar