Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to find the sum of 1 to 100 in C language

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to find the sum of 1 to 100 in C language". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn how to find the sum of 1 to 100 in C language.

Topic: ask for 1, 2, 3, 3 +. + 98 99 100

(1) solve the problem by mathematical method.

(2) write a C language program to solve the problem.

Solution:

(1) Mathematical method

S = 1 / 2 / 2 / 3 +. + 98 99 100 = (1 100) + (2 99) + (3 98) +. + (4952) + (5051) = 101 * 50 = 5050

(2) C language programming

# include int main () {int sum = 0; / / assign initial value for (int I = 1; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report