Ngôn ngữ Pascal:
program p1001(Input,Output);
var n:Integer;
begin
while not eof(Input) do
begin
Readln(n);
Writeln((1+n)*n/2);
end;
Ngôn ngữ C:
#include <stdio.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
printf("%d\n", (1 + n) * n / 2);
}
}
Ngôn ngữ C++:
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
cout << (1 + n) * n / 2 << '\n';
}
}
Ngôn ngữ Java:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println((n + 1) * n / 2);
}
}
}
Ngôn ngữ Python:
while True:
try:
n = int(input())
print((n + 1) * n // 2)
except:
break