백분율을 기준으로 가격 하락을 계산하려고합니다. 내가 손으로 쓰면 아래 방정식과 같이 간단하게 x = x-(x의 10 %) 또는 new_price = old_price-(old_price의 10 %)처럼 나옵니다. 따라서 100은 90이되고 90은 81이되는 식입니다. 나는 생각한다. 내가 브레인 파팅을하고 있는지, 무엇을하는지 잘 모르겠지만 이것을 실행하면 출력으로 "90"을 영원히 반복한다.
#include <stdio.h>
#include <math.h>
int pricedecrease(int x)
{
x = x - (x / 10.0);
return x;
}
int main(void)
{
int price = 100;
while(price > 3)
{
printf("%d\n", pricedecrease(price));
}
}
루프에서 가격 변수를 업데이트해야합니다. pricedecrease
함수를 호출 해도 price
변수가 수정되지 않습니다 .
#include <stdio.h>
#include <math.h>
int pricedecrease(int x)
{
x = x - (x / 10.0);
return x;
}
int main(void)
{
int price = 100;
while(price > 3)
{
printf("%d\n", price);
price = pricedecrease(price); // <- need to update price variable
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다