C 参考代码:
#include <stdio.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
printf("%d\n", (1 + n) * n / 2);
}
}
C++ 参考代码:
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
cout << (1 + n) * n / 2 << '\n';
}
}
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);
}
}
}
Python 参考代码:
while True:
try:
n = int(input())
print((n + 1) * n // 2)
except:
break