请写一段从1累加到1000的代码
时间: 2024-06-01 12:12:16 浏览: 130
以下是Python代码:
sum = 0
for i in range(1, 1001):
sum += i
print("1到1000的和为:", sum)
以下是Java代码:
int sum = 0;
for (int i = 1; i <= 1000; i++) {
sum += i;
}
System.out.println("1到1000的和为:" + sum);
以下是C++代码:
int sum = 0;
for (int i = 1; i <= 1000; i++) {
sum += i;
}
cout << "1到1000的和为:" << sum << endl;
以下是JavaScript代码:
let sum = 0;
for (let i = 1; i <= 1000; i++) {
sum += i;
}
console.log("1到1000的和为:" + sum);
阅读全文
相关推荐















