arrays - 数组在 C 中显示不同的输出
问题描述
这是我卡住的C语言代码。
#include<stdio.h>
int main(){
int Force_V[2], w;
int i, j, Disp_V[2];
printf("Enter Force Vector: ");
for(i=0; i<=2; i++){
scanf("%d", &Force_V[i]);
}
printf("Enter Displacement Vector: ");
for(j=0; j<=2; j++){
scanf("%d", &Disp_V[j]);
}
printf("Force vector: %di+%dj+%dk", Force_V[0],Force_V[1],Force_V[2]);
printf("\nDisplacement vector== %di+%dj+%dk", Disp_V[0],Disp_V[1],Disp_V[2]);
w= (Force_V[0]*Disp_V[0])+(Force_V[1]*Disp_V[1])+(Force_V[2]*Disp_V[2]);
printf("The work: %df", w);
return 0;
}
Force_V[2] 的输出显示 Disp_V[0] 的输出。谁能告诉我错误在哪里?
解决方案
该数组int Force_V[2]
有两个单元格,因此您必须像这样更改循环条件:
for(i=0; i<2; i++)
推荐阅读
- javascript - Web firebase.messaging().onMessage 未触发,但后台通知完美触发
- laravel - 如何在 Laravel 迁移中创建连接表?
- swift - 如何合并 2 个带有淡入淡出过渡的视频?
- javascript - 为什么我在 javascript 中得到奇怪的日期?
- c++ - 使用模板时可能是编译器中的 SFINAE BUG?
- asp.net-core - 在 IdentityServer4 和 ASP.NET Core 中检索客户端名称
- php - 如何将此响应xml转换为json
- python - 创建新类实例的替代方法
- awk - 如果它们在文件中,如何替换字符串
- python - 更新后pip3“TypeError:'module'对象不可调用”