Here is a code in C language I got stuck.
#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;
}
output for Force_V[2] is showing the output of Disp_V[0]. Can anyone tell me where's the error?
for (int i = 0; i < 3; i++)— this is the idiomatic form for a loop over an array of three elements.