我们的任务是创建一个程序,在其中输入一个向量,它返回该向量的每个第s个分量。例如,如果x =(1,2,3,4,5,6),s = 2,则输出为(1,3,5)。但我得到了一个zsh中止警告。
#include <stdio.h>
void sampleVector(double arr[], int n, int s){
int j = 0;
for (j=0; j<n; j++) {
arr[j] = 0;
printf("%d: ",j);
scanf("%lf",&arr[j]);
}
int i=1;
printf("%f,", arr[i]);
for (i=1; i<n; i++){
s=s*i;
printf("%f", arr[s]);
}
}
int main() {
int n;
scanf("%d", &n);
double arr[3]={0,0,0};
int s;
scanf("%d", &s);
sampleVector(arr, n, s);
}
这是我目前为止的计划!
1条答案
按热度按时间ruarlubt1#
https://godbolt.org/z/e3Tsa8GKj