Notice
Recent Posts
Recent Comments
Creative Code
genderRatio.cpp(static_cast) 본문
#include <stdio.h>
int main(void)
{
int men, women;
printf("남자 수 : ");
scanf("%d",&men);
printf("여자 수 : ");
scanf("%d",&women);
int total = men + women;
//double ratiom = 1.0 * men/total * 100;
//double ratiow =1.0 * women/total * 100;
double ratiom = static_cast<double>(men)/(double)(total) * (double) 100; //static_cast
double ratiow = static_cast<double>(women)/(total) * 100;
printf("남자 비율 : %.2f%%\n",ratiom);
printf("여자 비율 : %.2f%%\n",ratiow);
return 0;
}
'C++ Programming' 카테고리의 다른 글
string4(const_cast) (0) | 2023.09.08 |
---|---|
pointer3.cpp(reinterpret_cast) (0) | 2023.09.08 |
safeArray4(try-throw-catch) (0) | 2023.09.08 |
swap2(template 함수) (0) | 2023.09.08 |
boundArray2(template사용) (0) | 2023.09.08 |