I'm just now picking up C, so I'm pretty terrible since I'm coming from basic Python. I'm trying to print the elements in an array using a for-loop, but it's not coming out the right way.
#include <stdio.h>
#include <math.h>
int main()
{
int array[]={0,1,2,3,4};
int i;
for (i=0;i<5;i++);
{
printf("%d",array[i]);
}
printf("\n");
}
My output is
134513952
I have no clue why it's printing this.
<math.h>. You might want to separate the numbers from each other (spaces, or%2dor something). And you definitely don't want to go accessing out of the bounds of your array — the semicolon after theformeans you are accessingarray[5]which is out of bounds.01234, which is difficult to read. You might want change your format string from"%d"to" %d", so the numbers are shoved together.