SWEA 2019 더블더블

118.131.19.19 (토론)님의 2019년 11월 5일 (화) 10:16 판

1 개요

SWEA 2019 더블더블
  • 2를 반복해서 곱하면서 출력한다.
  • 다른 방법으로는 pow() 함수 사용을 생각해볼 수 있다.
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-2

2 C++

#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int t = 1;
    for(int i=0; i<=n ;i++) {
        cout << t << " ";
        t *= 2;
    }
}

3 Java

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0; i<=n; i++) {
            System.out.format("%d ", (int)Math.pow(2, i) );  
        }
    }
}

4 Python

  1. kcy

a = int(input())

for i in range(0, a+1):

   print(2**i,end=' ')

</source>

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}