So I have this exercise from my Coding class and we were tasked to input the user s input. However, we have to remove the comma of the last number of our output, and I m struggling with how to remove that comma. Can anyone please help?
这是我的法典。
#include <stdio.h>
#define MAX_SIZE 100
int main(){
int arr[MAX_SIZE];
int N, i;
int * ptr = arr;
printf("Enter length: ");
scanf("%d", &N);
for (i = 0; i < N; i++){
printf("Enter element %d: ", i+1);
scanf("%d", ptr);
ptr++;
}
ptr = arr;
printf("[");
for (i = 0; i < N; i++)
{
printf("%d,", *ptr);
ptr++;
}
printf("]");
return 0;
}
for convenience, this is the output I got
Enter length: 5
Enter element 1: 1
Enter element 2: 2
Enter element 3: 3
Enter element 4: 4
Enter element 5: 5
[1,2,3,4,5,]
这就是产出应如何
Enter length: 5
Enter element 1: 1
Enter element 2: 2
Enter element 3: 3
Enter element 4: 4
Enter element 5: 5
[1,2,3,4,5]