'how can I optimize this code so it won't use much RAM while compiling?
so basically the exercise's telling me to initialize an array and then display the elements while separing it with a comma.
#include <stdio.h>
int main(){
int Tab [5] = {5, 6, 0, 1, 5};
int i;
for (i=0 ; i<5 ; i++){
printf("%d", Tab[i]);
if (i < 4){
printf (" ,");
}
}
return 0;
}
My teacher told me that the problem is in the 'if statement', but I don't know how could I optimize it.
Solution 1:[1]
I'm not sure if it will help, because I don't see nothing wrong with the if in terms of RAM, but if your teacher told you that the if is the problem, then you can get rid of it:
for (i=0 ; i<4 ; i++){
printf("%d ,", Tab[i]);
}
printf("%d", Tab[i])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sagi |
