100程序代码怎么写

时间:2025-01-30 03:36:32 单机游戏

Java

```java

public class SumOfNumbers {

public static void main(String[] args) {

int sum = 0;

for (int i = 1; i <= 100; i++) {

sum += i;

}

System.out.println("Sum of numbers from 1 to 100 is " + sum);

}

}

```

C语言

```c

include

int main() {

int i, sum = 0;

for (i = 1; i <= 100; i++) {

sum += i;

}

printf("Sum of numbers from 1 to 100 is %d\n", sum);

return 0;

}

```

Python

```python

sum_of_numbers = sum(range(1, 101))

print("Sum of numbers from 1 to 100 is", sum_of_numbers)

```

C++

```cpp

include

int main() {

int sum = 0;

for (int i = 1; i <= 100; i++) {

sum += i;

}

std::cout << "Sum of numbers from 1 to 100 is " << sum << std::endl;

return 0;

}

```

JavaScript

```javascript

let sum = 0;

for (let i = 1; i <= 100; i++) {

sum += i;

}

console.log("Sum of numbers from 1 to 100 is " + sum);

```

这些代码示例分别使用Java、C语言、Python、C++和JavaScript编程语言实现了1到100所有整数求和的功能。你可以选择适合你的编程语言进行学习和使用。