题目:求1+2+3+ ……+n的值。
C++:
#include<iostream>
using namespace std;
int main(){
long long n;
cin>>n;
long long result;
result=(1+n)*n/2;
return 0
}
Java:
package UkingW;
import java.util.Scanner;
public class Begin2 {
public static void main(String[] args){
Scanner in=new Scanner(System in);
long n=in.nextLong();
in.close;
System.out.println((1+n)*n/2;
}
}