5050
5050是5049與5051之間的自然數。5050為高斯9岁時,小学老师提出的難題:“自然数从1到100的和”的答案。
| ||||
---|---|---|---|---|
| ||||
命名 | ||||
數字 | 5050 | |||
名稱 | 5050 | |||
小寫 | 五千零五十 | |||
大寫 | 伍仟零伍拾 | |||
序數詞 | 第五千零五十 five thousand fiftieth | |||
識別 | ||||
種類 | 整數 | |||
性質 | ||||
質因數分解 | 2×52×101 | |||
表示方式 | ||||
算筹 | ||||
二進制 | 1001110111010(2) | |||
八進制 | 11672(8) | |||
十二進制 | 2B0A(12) | |||
十六進制 | 13BA(16) | |||
在數學上
參考
以下示例了如何利用计算从自然数1到100的和。
C語言
#include <stdio.h>
int main()
{
int answer = 0;
int i = 1;
while (a <= 100)
{
answer = answer + i;
i = i + 1;
}
printf ("%d\n", answer);
return 0;
}
C++
#include <iostream>
using namespace std;
int main()
{
int answer = 0;
int i = 1;
while (i <= 100)
{
answer = answer + i;
i = i + 1;
}
cout << answer << endl;
return 0;
}
C#
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int answer = 0;
int i = 1;
while (i <= 100)
{
answer = answer + i;
i = i + 1;
}
Console.WriteLine(answer);
}
}
}
JavaScript
<html>
<head>
<title>Looping</title>
</head>
<body>
<SCRIPT language="JavaScript">
<!--
var answer = 0;
var i = 1;
while (i <= 100)
{
answer = answer + i;
i = i + 1;
}
document.write(answer);
//-->
</SCRIPT>
</body>
</html>
Java
package hellojava.java;
public class JAVA
{
public static void main(String[] args)
{
int answer = 0;
for(int i =1;i<=100;i++)
{
answer = answer + i;
}
System.out.println(answer);
}
}
MATLAB
i = 1;
answer = 0;
while i <= 100
answer = answer + i;
i = i + 1;
end
fprintf('%d\n',answer);
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.