杭电在线练习1001
(C)
include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
int sum=0;
for(int i=1;i<=n;i++)
sum+=i;
printf("%d\n\n",sum);
}
return 0;
}
(C++)
include
using namespace std;
int main()
{
int n;
while (cin >> n){
int sum = 0;
for (int i = 1; i <= n; i++)
sum += i;
cout << sum << endl << endl;
}
return 0;
}
(Java)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(input.hasNextInt()){
int n = input.nextInt();
int sum = 0;
for(int i = 1; i <= n; i++)
sum += i;
System.out.println(sum);
System.out.println();
}
}
}