当前位置:网站首页>2020-11-07
2020-11-07
2020-11-10 10:41:00 【osc_b88oux8w】
运用C#语言
1.求π/2的近似值的公式:
π/2=2/12/34/3*…2n/2n-12n/2n+1,求当n=1000时π的近似值
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
int n;
double pi=1;
for (n = 1; n <= 1000; n++)
{
pi=pi*2*n/(2*n-1)*2*n/(2*n+1);
}
Console.WriteLine("输出近似值: " +2*pi);
}
}
}

2.设计一个程序,输入一个十进制数,输出相应的十六进制数
using System;
namespace jinzhizhuanhuan
{
class Program
{
private static string result;
static void Main(string[] args)
{
Console.WriteLine("请输入十进制数: ");
int m = int.Parse(Console.ReadLine());
String result= Convert.ToString(m, 16);
Console.WriteLine("十六进制数为: " );
Console.WriteLine(m.ToString("X"));
}
}
}

3.找出数组a中最大值的下标,输出下标及最大值
using System;
namespace zuidazhix
{
class Program
{
static void Main(string[] args)
{
int max;
int i;
int j;
int[] her = new int[] {
89, 23, 45, 34, 34, 56, 6, 5, 9, 21 };
max = her[0];
for (i = 1; i < her.Length; i++)
{
if (her[i] > max)
{
max = her[i];
}
}
Console.WriteLine("最大值是: " + max);
for (j = 0; j < her.Length; j++)
{
if (her[j] == max) {
Console.WriteLine("下标是: "+j);
}
}
}
}
}

版权声明
本文为[osc_b88oux8w]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4375893/blog/4710537
边栏推荐
猜你喜欢

CSDN BUG1: to be added

ServiceManagerProxy中mRemote变量指的什么?

Connection to XXX could not be established. Broker may not be available

iNeuOS工业互联平台,WEB组态(iNeuView)增加工程视图导入、导出功能,及优化和修复,发布:v3.2.1版本

分布式文档存储数据库之MongoDB索引管理

CSDN bug6: to be added

For programmers, those unfamiliar and familiar computer hardware

mac终端Iterm2支持rz和sz的解决方案

Three ways to solve coursera video unable to watch

假如需要一百万个对象
随机推荐
CSDN BUG1: to be added
坚持追查7年,近10亿美元比特币终被美国政府没收充公
浅谈字节最新开源联邦机器学习平台Fedlearner
ASP.NET Core框架揭秘[博文汇总-持续更新]
csdn bug6:待加
CSDN bug9: to be added
史上最全异常检测算法概述
消防知识线上答题活动小程序复盘
C++ STL容器篇
learning to Estimate 3D Hand Pose from Single RGB Images论文理解
Wu Enda's refining notes on machine learning 4: basis of neural network - Zhihu
If you need a million objects
Several solutions to the problem that selenium webdriver always fails to use click
What can I do if I can't register didi? How to deal with it?
Promote China manufacturing upgrade, 3D visualization of production line in automobile assembly workshop
一个名为不安全的类Unsafe
Commodity management - merge purchase demand into purchase order
奸商加价销售mate40,小米可望在高端手机市场夺取更多市场
Mongodb index management of distributed document storage database
Assign the corresponding key and value in the map to the object