BOJ 8393 합

1 개요[ | ]

BOJ 8393 합
  • 1부터 N까지 합을 구합니다

2 C[ | ]

#include<stdio.h>
int main() {
	int N;
	scanf("%d", &N);
	int sum = 0;
	for(int i=1; i<=N; i++) sum += i;
	printf("%d\n", sum);
}

3 C++[ | ]

#include <iostream>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	int sum = 0;
	for(int i=1; i<=N; i++) sum += i;
	printf("%d\n", sum);
}

4 Java[ | ]

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        for( int i=1; i<=n; i++ ) {
            sum += i;
        }
        System.out.println(sum);
    }
}

5 Perl[ | ]

$sum += $_ for(1..<>);
printf("%s\n", $sum);

6 PHP[ | ]

<?php
fscanf(STDIN,"%d",$N);
$sum = 0;
for( $i=1; $i<=$N; $i++ ) {
    $sum += $i;
}
echo $sum;

7 Python[ | ]

n = int(input())
sum = 0
for i in range(1,n+1):
    sum += i
print( sum )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}