#include <iostream>
using namespace std;
int main() {
    int n;
    cout<<"请输入n:\n";
    cin>>n;
    cout<<"您输入的n是"<<n<<endl;
    int sum=0;
            for (int i=1;i<=n;i++){
                sum=sum+i;
            }
    cout << "从1到"<<n<<"的和为"<<sum <<endl;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: