c++ 질문입니다!
마중물
2023.04.01
c++반올림,올림,버림형식을 함수안에 넣긴했는데 한꺼번에 출력을 하려면 어떻게 써야하는지 모르겠어요.
돌려보면 숫자를 입력받고 값이 안나오고 바로 창이 꺼져버려요...
그리고 셋째 자리수가 5인경우 내림은 어떻게 해야하는지도 모르겠습니다ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
내용은 이렇습니다.
float형 숫자-100.0f n 100.0f를 입력받고, 소수점 셋째자리에서 반올림,올림,버림으로 출력!
단 음수 반올림시, 소수점 셋째 자리수가 5인경우 내림을한다.
#include stdio.h
int main()
{
double b;
int a;
double c;
printf(Input floating number -100.0f n 100.0f:\n);
scanf(%lf,&b);
if(-100.0f b 100.0f)
{
a=(int)(b*100+0.5);
c=(double)a/100;
printf(round half up:\n,c);
a=(int)(b*100+1);
c=(double)a/100;
printf(round up:\n,c);
a=(int)(b*100);
c=(double)a/100;
printf(round down:\n,c);
}
return 0;
}
어디를 어떻게 고쳐야 하죠 ㅠㅠㅠㅠㅠㅠㅠㅠ