当前位置:网站首页>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
边栏推荐
- 商品管统——采购需求合并到采购单
- 解决Coursera视频无法观看的三种方法(亲测有效)
- OSChina 周二乱弹 —— 我养的绿植分别为土豆,生姜,蒜
- selenium webdriver使用click一直失效问题的几种解决方法
- [论文阅读笔记] RoSANE, Robust and scalable attributed network embedding for sparse networks
- GNU assembly basic mathematical equations multiplication
- 仅发送options请求,没有发送post解决方案
- 使用call、apply和bind解决js中烦人的this,事件绑定时的this和传参问题
- [paper reading notes] community oriented attributed network embedding
- 编码风格:Mvc模式下SSM环境,代码分层管理
猜你喜欢

《Python Cookbook 3rd》笔记(2.1):使用多个界定符分割字符串
![[paper reading notes] network embedding with attribute refinement](/img/71/760f29f8a13b366cf3bad4fb48bd63.jpg)
[paper reading notes] network embedding with attribute refinement

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

CSDN bug6: to be added

从大专生到蚂蚁金服CTO,他写下“支付宝”第一行代码:逆风的方向,更适合飞翔!...

learning to Estimate 3D Hand Pose from Single RGB Images论文理解

YouTube subscription: solve the problem of incomplete height display of YouTube subscription button in pop-up window

《Python Cookbook 3rd》笔记(2.2):字符串开头或结尾匹配

csdn bug6:待加

Coding style: SSM environment in MVC mode, code hierarchical management
随机推荐
selenium webdriver使用click一直失效问题的几种解决方法
On fedlearner, the latest open source federated machine learning platform of byte
iNeuOS工业互联平台,WEB组态(iNeuView)增加工程视图导入、导出功能,及优化和修复,发布:v3.2.1版本
getIServiceManager() 源码分析
[leetcode] 93 balanced binary tree
[paper reading notes] network embedding with attribute refinement
[paper reading notes] a multilayered informational random walk for attributed social network embedding
[paper reading notes] rosane, robust and scalable attributed network embedding for sparse networks
初级工程师如何在职场生存
Seam engraving algorithm: a seemingly impossible image size adjustment method
走进C# abstract,了解抽象类与接口的异同
An unsafe class named unsafe
Explanation of Z-index attribute
[paper reading notes] large scale heterogeneous feature embedding
CSDN bug4: to be added
Use call, apply and bind to solve the annoying this in JS, this in event binding and parameter passing
csdn bug11:待加
Network security engineer Demo: original * * controls your server like this! (2)
CSDN bug6: to be added
CSDN bug11: to be added