문제 링크입니다: www.acmicpc.net/problem/2052
2052번: 지수연산
자연수 N(1≤N≤250)이 주어졌을 때, 2의 -N승을 계산하는 프로그램을 작성하시오. 즉, 1/(2^N)을 계산하는 것이다.
www.acmicpc.net
scientific notation 없이 모든 소수점을 출력하는 것이 핵심이였는데 이는 printf("%.*f", 자릿수, 출력하고자 하는 실수); 와 같은 문법으로 가능합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
double result = pow(0.5, N); | |
printf("%.*f\n", N, result); | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2438번 별 찍기 - 1 (0) | 2021.04.14 |
---|---|
백준 2061번 좋은 암호 (0) | 2021.04.11 |
백준 1975번 Number Game (0) | 2021.04.09 |
백준 21300번 Bottle Return (2) | 2021.04.08 |
백준 1952번 달팽이2 (2) | 2021.04.07 |