当前位置: 首页 > news >正文

网站首页被k怎么办汤阴县seo快速排名有哪家好

网站首页被k怎么办,汤阴县seo快速排名有哪家好,软文发稿网,网站建设与管理必修练习 1#xff1a;计算圆的周长和面积 改编题目#xff1a;编写一个 C# 程序#xff0c;让用户输入圆的半径#xff0c;然后计算并输出该圆的周长和面积#xff0c;结果保留两位小数。 using System;class CircleCalculation {static void Main(){const double pi 3.14…练习 1计算圆的周长和面积 改编题目编写一个 C# 程序让用户输入圆的半径然后计算并输出该圆的周长和面积结果保留两位小数。 using System;class CircleCalculation {static void Main(){const double pi 3.14;Console.Write(请输入圆的半径);int n int.Parse(Console.ReadLine());double circumference 2 * pi * n;double area pi * n * n;Console.WriteLine($半径为 {n} 的圆的周长为{circumference:F2});Console.WriteLine($半径为 {n} 的圆的面积为{area:F2});} }练习 2两个变量值交换两种方法 改编题目编写一个 C# 程序实现两个整数变量值的交换分别使用临时变量和不使用临时变量两种方法并输出交换后的结果 using System;class VariableSwap {static void Main(){// 方法一使用临时变量int a 8, b 19;int temp a;a b;b temp;Console.WriteLine($使用临时变量交换后a{a}, b{b});// 方法二不使用临时变量a 8;b 19;a a b;b a - b;a a - b;Console.WriteLine($不使用临时变量交换后a{a}, b{b});} }练习 3输入 3 个数从小到大输出 改编题目编写一个 C# 程序让用户输入 3 个整数然后将这 3 个数从小到大排序并输出。 using System;class SortThreeNumbers {static void Main(){Console.Write(请您输入 3 个整数用空格区分开);string[] input Console.ReadLine().Split( );int a int.Parse(input[0]);int b int.Parse(input[1]);int c int.Parse(input[2]);if (a b){int temp a;a b;b temp;}if (a c){int temp a;a c;c temp;}if (b c){int temp b;b c;c temp;}Console.WriteLine($从小到大排序为{a} {b} {c});} }练习 4根据学生成绩输出等级 改编题目编写一个 C# 程序让用户输入一个 0 - 100 之间的学生成绩根据成绩输出对应的等级60 分以下为不及格60 - 69 为合格70 - 79 为良80 - 89 为优90 以上为超神。 using System;class GradeEvaluation {static void Main(){Console.Write(请输入学生成绩0 - 100);int score int.Parse(Console.ReadLine());if (score 60){Console.WriteLine(不及格);}else if (score 60 score 69){Console.WriteLine(合格);}else if (score 70 score 79){Console.WriteLine(良);}else if (score 80 score 89){Console.WriteLine(优);}else{Console.WriteLine(超神);}} }练习 5求 0 - 100 之间所有偶数和奇数的和 改编题目编写一个 C# 程序计算 0 - 100 之间所有偶数的和以及所有奇数的和并分别输出结果。 using System;class EvenOddSum {static void Main(){int evenSum 0;int oddSum 0;for (int i 0; i 100; i){if (i % 2 0){evenSum i;}else{oddSum i;}}Console.WriteLine(0 - 100 之间所有偶数的和为 evenSum);Console.WriteLine(0 - 100 之间所有奇数的和为 oddSum);} }练习 6求 10 的阶乘 改编题目编写一个 C# 程序计算 10 的阶乘并输出结果。 using System;class FactorialCalculation {static void Main(){int result 1;for (int i 1; i 10; i){result * i;}Console.WriteLine(10 的阶乘为 result);} }练习 7反向输出数字 改编题目编写一个 C# 程序让用户输入一个整数然后将该整数反向输出。 using System;class ReverseNumber {static void Main(){Console.Write(请输入一个整数);int num int.Parse(Console.ReadLine());int reversed 0;while (num ! 0){reversed reversed * 10 num % 10;num / 10;}Console.WriteLine(反向输出的数字为 reversed);} }练习 8输出指定形状 改编题目编写一个 C# 程序在屏幕上输出如下形状 * ** *** **** ***** ******using System;class ShapeOutput1 {static void Main(){for (int i 1; i 6; i){for (int j 0; j i; j){Console.Write(*);}Console.WriteLine();}} }练习 10单循环输出指定形状 改编题目编写一个 C# 程序使用单循环在屏幕上输出如下形状 * ** *** **** ***** ******using System;class ShapeOutputSingleLoop {static void Main(){string stars ;for (int i 1; i 6; i){stars *;Console.WriteLine(stars);}} }练习 11输出指定对称形状 改编题目编写一个 C# 程序在屏幕上输出如下形状 * *** ***** ******* ********* ******* ***** *** *using System;class SymmetricShapeOutput {static void Main(){int maxStars 9;for (int i 1; i maxStars; i 2){for (int j 0; j (maxStars - i) / 2; j){Console.Write( );}for (int k 0; k i; k){Console.Write(*);}Console.WriteLine();}for (int i maxStars - 2; i 1; i - 2){for (int j 0; j (maxStars - i) / 2; j){Console.Write( );}for (int k 0; k i; k){Console.Write(*);}Console.WriteLine();}} }练习 12打印 9 * 9 乘法表 改编题目编写一个 C# 程序打印 9 * 9 乘法表。 using System;class MultiplicationTable {static void Main(){for (int i 1; i 9; i){for (int j 1; j i; j){Console.Write(${j} * {i} {i * j}\t);}Console.WriteLine();}} }练习 13找出 100 到 999 之间的水仙花数两种方法 改编题目编写一个 C# 程序找出 100 到 999 之间的所有水仙花数分别使用单循环和嵌套循环两种方法。 using System;class NarcissisticNumbersSingleLoop {static void Main(){for (int num 100; num 1000; num){int hundreds num / 100;int tens (num / 10) % 10;int units num % 10;if (hundreds * hundreds * hundreds tens * tens * tens units * units * units num){Console.WriteLine(num);}}} }C# 代码嵌套循环 using System;class NarcissisticNumbersNestedLoop {static void Main(){for (int i 1; i 9; i){for (int j 0; j 9; j){for (int k 0; k 9; k){int num i * 100 j * 10 k;if (i * i * i j * j * j k * k * k num){Console.WriteLine(num);}}}}} }练习 14组成不重复的三位数 改编题目编写一个 C# 程序使用 1、2、3、4 四个数字找出能组成多少个不相同且无重复数字的三位数并输出这些三位数。 using System;class ThreeDigitNumbers {static void Main(){int count 0;for (int i 1; i 4; i){for (int j 1; j 4; j){if (j i) continue;for (int k 1; k 4; k){if (k i || k j) continue;int num i * 100 j * 10 k;Console.WriteLine(num);count;}}}Console.WriteLine(能组成的不相同且无重复数字的三位数共有 count 个);} }练习 15歌星大赛打分计算平均分 改编题目编写一个 C# 程序模拟歌星大赛打分过程。假设有 100 个评委给选手打分分值在 1 - 100 之间去掉一个最高分和一个最低分后计算剩余 98 个分数的平均分作为选手的最后得分。 using System;class SingerCompetitionScore {static void Main(){Random random new Random();int[] scores new int[100];for (int i 0; i 100; i){scores[i] random.Next(1, 101);}int maxScore scores[0];int minScore scores[0];int totalScore 0;foreach (int score in scores){if (score maxScore) maxScore score;if (score minScore) minScore score;totalScore score;}totalScore totalScore - maxScore - minScore;double averageScore (double)totalScore / 98;Console.WriteLine(选手的最后得分是 averageScore);} }练习 16可乐兑换问题 改编题目已知 3 个可乐瓶可以换一瓶可乐现在有 364 瓶可乐编写一个 C# 程序计算一共可以喝多少瓶可乐最后剩下几个空瓶。 using System;class ColaExchange {static void Main(){int totalCola 364;int emptyBottles 364;while (emptyBottles 3){int exchangedCola emptyBottles / 3;totalCola exchangedCola;emptyBottles emptyBottles % 3 exchangedCola;}Console.WriteLine(一共可以喝 totalCola 瓶可乐剩下 emptyBottles 个空瓶。);} }练习 17兔子繁殖问题 改编题目有一对兔子从出生后第 3 个月起每个月都生一对兔子小兔子长到第三个月后每个月又生一对兔子。假如兔子都不死编写一个 C# 程序计算第 1 到第 20 个月里每个月的兔子总数。 using System;class RabbitReproduction {static void Main(){int[] rabbits new int[20];rabbits[0] 1;rabbits[1] 1;for (int i 2; i 20; i){rabbits[i] rabbits[i - 1] rabbits[i - 2];}for (int i 0; i 20; i){Console.WriteLine($第 {i 1} 个月的兔子总数为{rabbits[i]} 对);}} }练习 18百钱百鸡问题 改编题目编写一个 C# 程序解决百钱百鸡问题。已知公鸡 5 元一只母鸡 3 元一只小鸡 1 元 3 只现在有 100 元钱要买 100 只鸡找出所有可能的购买方案并输出。 C# 代码 using System;class HundredMoneyHundredChickens {static void Main(){for (int rooster 0; rooster 20; rooster){for (int hen 0; hen 33; hen){int chick 100 - rooster - hen;if (chick % 3 0 rooster * 5 hen * 3 chick / 3 100){Console.WriteLine($公鸡{rooster} 只母鸡{hen} 只小鸡{chick} 只);}}}} } 练习 19输出一个 120 - 245 之间的随机数 改编题目编写一个 C# 程序模拟抽奖活动每次运行程序时从 120 到 245 这个区间内随机抽取一个幸运号码并输出。 using System;class RandomNumberInRange {static void Main(){Random random new Random();int luckyNumber random.Next(120, 246);Console.WriteLine($本次抽奖的幸运号码是: {luckyNumber});} }练习 20猜数字游戏 设计一个 C# 程序实现猜数字游戏。程序会随机生成一个 0 到 50 之间的整数玩家需要猜测这个数字。每次猜测后程序会提示玩家猜大了、猜小了还是猜对了直到玩家猜对为止。同时记录玩家猜测的次数并在猜对后输出。 using System;class GuessTheNumberGame {static void Main(){Random random new Random();int secretNumber random.Next(0, 51);int guess;int attempts 0;Console.WriteLine(我心里想了一个 0 到 50 之间的数字你可以开始猜啦);do{Console.Write(请输入你猜测的数字: );guess int.Parse(Console.ReadLine());attempts;if (guess secretNumber){Console.WriteLine($你猜小了这个数字比 {guess} 大。);}else if (guess secretNumber){Console.WriteLine($你猜大了这个数字比 {guess} 小。);}else{Console.WriteLine($恭喜你猜对了这个数字就是 {secretNumber}。你一共用了 {attempts} 次猜测。);}} while (guess ! secretNumber);} }练习 21初始化数组并倒序输出 改编题目编写一个 C# 程序创建一个包含 10 个元素的整数数组使用随机数为数组元素赋值范围为 1 - 100然后将数组元素倒序排列并输出。 using System;class ReverseRandomArray {static void Main(){int[] array new int[10];Random random new Random();// 用随机数初始化数组for (int i 0; i array.Length; i){array[i] random.Next(1, 101);}// 倒序数组Array.Reverse(array);// 输出倒序后的数组Console.WriteLine(倒序后的数组元素为:);foreach (int num in array){Console.Write(num );}Console.WriteLine();} }练习 22初始化数组并乱序输出两种方法 改编题目在 C# 中创建一个包含 10 个元素的数组元素值为 0 到 10然后使用两种不同的方法将数组元素打乱顺序并输出。 using System;class ShuffleArray {static void Main(){int[] array new int[10];for (int i 0; i array.Length; i){array[i] i;}// 方法一使用 Random 类交换元素int[] shuffledArray1 (int[])array.Clone();Random random new Random();for (int i shuffledArray1.Length - 1; i 0; i--){int j random.Next(i 1);int temp shuffledArray1[i];shuffledArray1[i] shuffledArray1[j];shuffledArray1[j] temp;}Console.WriteLine(方法一乱序后的数组:);foreach (int num in shuffledArray1){Console.Write(num );}Console.WriteLine();// 方法二使用 List 和 Random 类System.Collections.Generic.Listint list new System.Collections.Generic.Listint(array);int[] shuffledArray2 new int[list.Count];for (int i 0; i shuffledArray2.Length; i){int index random.Next(list.Count);shuffledArray2[i] list[index];list.RemoveAt(index);}Console.WriteLine(方法二乱序后的数组:);foreach (int num in shuffledArray2){Console.Write(num );}Console.WriteLine();} }练习 23一维数组奇数偶数分区 改编题目编写一个 C# 程序创建一个包含 20 个元素的一维数组使用随机数范围 1 - 100初始化数组。然后将数组中的奇数元素移到数组左边偶数元素移到数组右边并输出分区后的数组。 using System;class OddEvenPartition {static void Main(){int[] array new int[20];Random random new Random();// 用随机数初始化数组for (int i 0; i array.Length; i){array[i] random.Next(1, 101);}// 分区操作int left 0;int right array.Length - 1;while (left right){while (left right array[left] % 2 ! 0){left;}while (left right array[right] % 2 0){right--;}if (left right){int temp array[left];array[left] array[right];array[right] temp;}}// 输出分区后的数组Console.WriteLine(分区后的数组:);foreach (int num in array){Console.Write(num );}Console.WriteLine();} }练习 24数组排序选择、冒泡、插入 改编题目编写一个 C# 程序创建一个包含 10 个随机整数范围 1 - 100的数组分别使用选择排序、冒泡排序和插入排序算法对数组进行排序并输出排序后的数组。 using System;class ArraySorting {static void Main(){int[] array new int[10];Random random new Random();// 用随机数初始化数组for (int i 0; i array.Length; i){array[i] random.Next(1, 101);}// 选择排序int[] selectionSorted (int[])array.Clone();for (int i 0; i selectionSorted.Length - 1; i){int minIndex i;for (int j i 1; j selectionSorted.Length; j){if (selectionSorted[j] selectionSorted[minIndex]){minIndex j;}}int temp selectionSorted[i];selectionSorted[i] selectionSorted[minIndex];selectionSorted[minIndex] temp;}Console.WriteLine(选择排序后的数组:);foreach (int num in selectionSorted){Console.Write(num );}Console.WriteLine();// 冒泡排序int[] bubbleSorted (int[])array.Clone();for (int i 0; i bubbleSorted.Length - 1; i){for (int j 0; j bubbleSorted.Length - i - 1; j){if (bubbleSorted[j] bubbleSorted[j 1]){int temp bubbleSorted[j];bubbleSorted[j] bubbleSorted[j 1];bubbleSorted[j 1] temp;}}}Console.WriteLine(冒泡排序后的数组:);foreach (int num in bubbleSorted){Console.Write(num );}Console.WriteLine();// 插入排序int[] insertionSorted (int[])array.Clone();for (int i 1; i insertionSorted.Length; i){int key insertionSorted[i];int j i - 1;while (j 0 insertionSorted[j] key){insertionSorted[j 1] insertionSorted[j];j--;}insertionSorted[j 1] key;}Console.WriteLine(插入排序后的数组:);foreach (int num in insertionSorted){Console.Write(num );}Console.WriteLine();} }练习 25二维数组2 * 3赋值两种方法单循环、嵌套循环 改编题目编写一个 C# 程序创建一个 2 行 3 列的二维整数数组分别使用单循环和嵌套循环的方法为数组元素赋值赋值规则为从 1 开始依次递增并输出数组元素。 using System;class TwoDimensionalArrayAssignment {static void Main(){int[,] array new int[2, 3];// 方法一单循环赋值int index 1;for (int i 0; i array.GetLength(0); i){for (int j 0; j array.GetLength(1); j){array[i, j] index;}}Console.WriteLine(单循环赋值后的数组:);for (int i 0; i array.GetLength(0); i){for (int j 0; j array.GetLength(1); j){Console.Write(array[i, j] );}Console.WriteLine();}// 方法二嵌套循环赋值index 1;for (int i 0; i array.GetLength(0); i){for (int j 0; j array.GetLength(1); j){array[i, j] index;}}Console.WriteLine(嵌套循环赋值后的数组:);for (int i 0; i array.GetLength(0); i){for (int j 0; j array.GetLength(1); j){Console.Write(array[i, j] );}Console.WriteLine();}} }练习 26数组内容拷贝 改编题目编写一个 C# 程序有一个 2 行 3 列的二维数组 arr1其元素值为 {{1, 2, 3}, {4, 5, 6}}将该数组的元素按顺序拷贝到一个 3 行 2 列的二维数组 arr2 中并输出 arr2 的元素。 using System;class ArrayCopying {static void Main(){int[,] arr1 { { 1, 2, 3 }, { 4, 5, 6 } };int[,] arr2 new int[3, 2];int row 0;int col 0;for (int i 0; i arr1.GetLength(0); i){for (int j 0; j arr1.GetLength(1); j){arr2[row, col] arr1[i, j];col;if (col arr2.GetLength(1)){col 0;row;}}}Console.WriteLine(拷贝后的数组 arr2:);for (int i 0; i arr2.GetLength(0); i){for (int j 0; j arr2.GetLength(1); j){Console.Write(arr2[i, j] );}Console.WriteLine();}} }练习 28初始化特定数组两种方法 改编题目在 C# 中使用两种不同的方法初始化一个 9 行 9 列的二维数组数组元素按照如下规律排列 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 2 3 3 3 3 3 2 1 1 2 3 4 4 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 4 4 3 2 1 1 2 3 3 3 3 3 2 1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1using System;class SpecialArrayInitialization {static void Main(){int[,] array new int[9, 9];// 方法一嵌套循环手动赋值for (int i 0; i 9; i){for (int j 0; j 9; j){int min Math.Min(i, j);min Math.Min(min, 8 - i);min Math.Min(min, 8 - j);array[i, j] min 1;}}Console.WriteLine(方法一初始化后的数组:);for (int i 0; i 9; i){for (int j 0; j 9; j){Console.Write(array[i, j] );}Console.WriteLine();}// 方法二分层赋值int[,] array2 new int[9, 9];for (int layer 0; layer 5; layer){for (int i layer; i 9 - layer; i){for (int j layer; j 9 - layer; j){array2[i, j] layer 1;}}}Console.WriteLine(方法二初始化后的数组:);for (int i 0; i 9; i){for (int j 0; j 9; j){Console.Write(array2[i, j] );}Console.WriteLine();}} }练习 29输出杨辉三角二维数组法n 层 改编题目 编写一个 C# 程序让用户输入一个正整数 n然后使用二维数组的方法输出 n 层的杨辉三角。 using System;class PascalTriangle {static void Main(){Console.Write(请输入要输出的杨辉三角的层数: );int n int.Parse(Console.ReadLine());int[,] triangle new int[n, n];for (int i 0; i n; i){for (int j 0; j i; j){if (j 0 || j i){triangle[i, j] 1;}else{triangle[i, j] triangle[i - 1, j - 1] triangle[i - 1, j];}}}Console.WriteLine(杨辉三角:);for (int i 0; i n; i){for (int k 0; k n - i - 1; k){Console.Write( );}for (int j 0; j i; j){Console.Write(triangle[i, j].ToString().PadLeft(4));}Console.WriteLine(); 结语C#初级教程到此结束感谢努力进步的你愿你学习之路一路繁花。
http://www.dnsts.com.cn/news/81369.html

相关文章:

  • 网站文章做百度排名软件制作小程序开发
  • 在百度怎么建自己的网站比较好的网站建设技术开发
  • 建站网站案例搭建网站钱
  • 鹤壁网站建设兼职广告主
  • 河南郑州广告公司网站建设女性门户网站模板
  • 摄影网站设计说明书企业培训体系搭建
  • 站内推广的几种方式珠宝网站谁家做的好
  • 电子行业网站建设折再返怎么 做网站
  • 阜阳市城乡建设 档案馆网站江苏建设职业技术学院
  • 实时定量引物设计网站怎么做哪个网站做推广效果好
  • 大兴模版网站建设哪家好美工在网站建设中的作用
  • 网站功能建设规划书揭阳新闻最新消息
  • 网站建设开发服务费怎么做分录深圳住建局官方网电话
  • 做网站最专业2022最新新闻大事件
  • 青岛正规网站建设哪家好单位举报网站建设维护情况报告
  • 免费网站网站制作平台网站案例展示怎么做
  • 公司网站图片传不上去深圳手机端网站建设收费
  • 创业网站怎么做宣传片拍摄哪个好
  • 怎么建设微信网站做优化的网站
  • 外卖网站的建设与推广it外包价格
  • 维护网站计划书深圳低价建站
  • 网站做优化好还是推广好西安华为公司
  • 电子商务网站建设模板梅州建站网络科技有限公司
  • 贵港网站建设动态中英文网站是怎么做的
  • pa66用途障车做网站网站建设报价单 excel
  • 龙港做网站怎么给网站做关键词
  • 微信网站域名wordpress固定链接设置自定义结构
  • 做网站需要的服务器wordpress 网站标题
  • 创建网站的目的wordpress更改主题背景
  • wap网站开发培训做平台