当前位置:网站首页>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
边栏推荐
- mac终端Iterm2支持rz和sz的解决方案
- selenium webdriver使用click一直失效问题的几种解决方法
- 寻找性能更优秀的不可变小字典
- csdn bug7:待加
- 史上最全异常检测算法概述
- Understanding of learning to estimate 3D hand pose from single RGB images
- Graph undirected graph
- B. protocal has 7000eth assets in one week!
- After seven years of pursuing, nearly one billion US dollars of bitcoin was eventually confiscated and confiscated by the US government
- Experiment 2
猜你喜欢
Hong Kong listed companies transfer cards to acquire 42.5% equity of chuangxinzhong and plan to speed up the distribution of marketing services
我手撸了一个划线翻译工具!
jt-day10
对于程序员,那些既陌生又熟悉的计算机硬件
港股上市公司移卡收购创信众42.5%股权 谋划加快营销服务布局
Oschina: my green plants are potatoes, ginger and garlic
一幅图像能顶16x16字!——用于大规模图像缩放识别的变压器(对ICLR 2021年论文的简要回顾)
Key layout of the Central Government: in the next five years, self-reliance and self-improvement of science and technology will be the priority, and these industries will be named
GNU assembly language uses inline assembly to extend ASM
一个名为不安全的类Unsafe
随机推荐
推动中国制造升级,汽车装配车间生产流水线 3D 可视化
csdn bug3:待加
leetcode1-两数之和
《Python Cookbook 3rd》笔记(2.2):字符串开头或结尾匹配
CSDN bug10: to be added
csdn bug4:待加
【技术教程】Visual Studio 2017自建WebRTC中peerconnection_client程序报LNK2019 无法解析的外部符号错误
Yixian e-commerce prospectus of perfect diary parent company: focusing on marketing and ignoring R & D, with a loss of 1.1 billion in the first three quarters
An unsafe class named unsafe
Simple use of JMeter
jmeter接口测试--带有token的解决方法
GNU assembly language uses inline assembly to extend ASM
ASP.NET Core框架揭秘[博文汇总-持续更新]
Problems and solutions in configuring FTP server with FileZilla server
安卓快速关机APP
C + + STL container
learning to Estimate 3D Hand Pose from Single RGB Images论文理解
The length of the last word in leetcode
jt-day10
我手撸了一个划线翻译工具!