C언어 질문입니다.
글쓴이: 2080fresh / 작성시간: 금, 2018/04/13 - 4:11오후
#include <stdio.h>
int main()
{
double pos[3];
double vel[3];
double t_i = 1;
printf("Initial position r(0) = [x(0) y(0) z(0)] = ");
scanf("%lf%lf%lf", pos[0], pos[1], pos[2]);
while (t_i != 0)
{
printf("\n\tTime interval t_i\t\t= ");
scanf("%lf", &t_i);
if (t_i < 0) {
printf("Please input positive time interval\n");
continue;
}
printf("Velocity\t\t[Vx Vy Vz] = ");
scanf("%lf%lf%lf", vel[0], vel[1], vel[2]);
for (int i = 0; i < 3; i++) {
pos[i] = pos[i] + (t_i*vel[i]);
}
printf("\t\t\tr(%.2f) = [%6.2f%6.2f%6.2f]", t_i, pos[0], pos[1], pos[2]);
}
return 0;
}문제는 첨부했습니다.
실행시키면 initialp osition입력은 하라고 하고 입력하면 프로그램이 멈춰버립니다. 컴파일도 문제없이 진행되서 뭐가 문제인지 고민입니다 도와주시면 감사하겠습니다!
File attachments:
| 첨부 | 파일 크기 |
|---|---|
| 35.4 KB |
Forums:


scanf("%lf%lf%lf", vel[0],
---
http://coolengineer.com
감사합니다@
그런데 위에 pos를 입력받을때는 &를 안쓰고 왜 거기서는 &를 써야되나요? 그렇게 바꿔도 마찬가지로 frist position을 입력받자마자 프로그램이 멈춥니다.
& 를 써야하는 이유가 궁금한 건가요, 아니면 pos
& 를 써야하는 이유가 궁금한 건가요, 아니면 pos[] 는 왜 지적하지 않느냐는 항의인가요 ?
그래도 멈춘 것 처럼 보인다면, 안 멈췄으니 printf() 가 출력해야 할 것이 '\n' 으로 끝나지 않는 모든 곳에 fflush(stdout) 을 추가하세요.
debug를 해보시기 바랍니다. 각 라인마다 step
debug를 해보시기 바랍니다. 각 라인마다 step-by-step 으로 진행하다 보면 다 직접 해결 하실 수 있습니다. ~~
댓글 달기