누군가 다음 코드가 표시된 행에 0
을 출력하는 이유를 설명해 주시겠습니까?왜이 정수 나누기가 0입니까?
마치 모든 것이 정확한 것처럼 보이지만 끝 근처에서 결과를 얻으려고하면 매번 0이됩니다. 한마디로
#include <stdio.h>
int main() {
// Gather time-lapse variables
int frameRate, totalLengthSecs;
printf("How many frames per second: ");
scanf("%i", &frameRate);
printf("--> %i frames confirmed.", frameRate);
printf("\nDesired length of time-lapse [secs]: ");
scanf("%i", &totalLengthSecs);
printf("--> %i seconds confirmed.", totalLengthSecs);
int totalFrames = frameRate * totalLengthSecs;
printf("\nYou need %i frames.", totalFrames);
// Time-lapse interval calculation
int timeLapseInterval = totalLengthSecs/totalFrames;
printf("\n\n%i", timeLapseInterval); // <-- this prints 0
return 0;
}
"원하는 시간의 경과 시간"에 대해 "표준 입력"으로 무엇을 입력하고 있습니까? –
'totalLengthSecs/totalFrames'가 1보다 작 으면 모든 값이 부동 소수점 숫자가 아닌 정수이기 때문에 0으로 절단됩니다. –