error sorting array in c language -
program write number of goals scored each player in arranged list
sorting array in c language code showing error "did not evaluate constant" in visual studio.
int main() { int i,temp,swaped; int howmany = 10; int goal[howmany]; (i = 0;i <= howmany;i++) { goal[i] = (rand() % 40)+1; } printf("orignal list"); (i = 0;i <= howmany;i++) { printf("%d \n", goal[i]); } while (1) { swaped = 0; (i = 0;i < howmany;i++) { if (goal[i] > goal[i + 1]) { goal[i] = temp; goal[i] = goal[i + 1]; goal[i + 1] = temp; swaped = 1; } } if (swapped == 0) { break; } printf("sorted list"); (i = 0;i < howmany;i++) { printf("%d \n", goal[i]); } } _getch(); return 0; }
visual studio 2013 has old , creaky c compiler which, after these years, still not yet understand c99. you'll need change this:
int howmany = 10; int goal[howmany]; to:
#define howmany 10 int goal[howmany];
Comments
Post a Comment