1 class Program 2 { 3 /// <summary> 4 /// 100以内与7有关的数字 5 /// </summary> 6 public void shuzi() 7 { 8 for (int i = 1; i <= 100; i++) 9 { 10 if (i % 10 == 7 || i / 10 == 7 || i % 7 == 0) 11 { 12 Console.Write(i + "\t"); 13 } 14 } 15 } 16 /// <summary> 17 /// 闯关分数 18 /// </summary> 19 /// <param name="a"></param> 20 /// <returns></returns> 21 public int chuangguan(int a) 22 { 23 int sum = 0; 24 for (int i = 0; i <= a; i++) 25 { 26 if (i <= 20) 27 { 28 sum += i; 29 } 30 else if (i > 20 && i <= 30) 31 { 32 sum += 10; 33 } 34 else if (i > 30 && i <= 40) 35 { 36 sum += 20; 37 } 38 else if (i > 40 && i < 50) 39 { 40 sum += 30; 41 } 42 else 43 { 44 sum += 100; 45 } 46 } 47 return sum; 48 } 49 /// <summary> 50 /// 9*9乘法表 51 /// </summary> 52 public void chengfabiao() 53 { 54 for (int i = 1; i < 10; i++) 55 { 56 for (int l = 1; l <= i; l++) 57 { 58 Console.Write(l + "*" + i + "=" + (i * l) + "\t"); 59 } 60 Console.WriteLine(); 61 } 62 } 63 /// <summary> 64 /// 100以内奇数和 65 /// </summary> 66 /// <returns></returns> 67 public int jishu() 68 { 69 int sum = 0; 70 for (int i = 1; i < 100; i += 2) 71 { 72 sum += i; 73 } 74 return sum; 75 } 76 /// <summary> 77 /// 凑钱 78 /// </summary> 79 public void qian() 80 { 81 int sum = 0; 82 for (int i = 0; i <= 60; i++) 83 { 84 for (int l = 0; l <= 30; l++) 85 { 86 for (int j = 0; j <= 12; j++) 87 { 88 if (i + l * 2 + j * 5 == 60) 89 { 90 sum++; 91 Console.WriteLine("第" + sum + "种打法:需要{0}个一毛的,{1}个两毛的,{2}个五毛的。", i, l, j); 92 } 93 } 94 } 95 } 96 Console.Write("共有" + sum + "种打法。"); 97 } 98 /// <summary> 99 /// 求方程 100 /// </summary> 101 /// <param name="a"></param> 102 /// <returns></returns> 103 public double fangcheng(double a) 104 { 105 double y; 106 if (a < 1) 107 { 108 y = a; 109 } 110 else if (a >= 1 && a < 10) 111 { 112 y = 2 * a - 1; 113 } 114 else 115 { 116 y = 3 * a - 11; 117 } 118 return y; 119 } 120 /// <summary> 121 /// 每个学生的平均分 122 /// </summary> 123 /// <param name="a"></param> 124 public void renpingjun(double[,] a) 125 { 126 double[,] fenshu = new double[10, 5]; 127 fenshu = a; 128 for (int i = 0; i < 10; i++) 129 { 130 double sum = 0; 131 for (int l = 0; l < 5; l++) 132 { 133 sum += fenshu[i, l]; 134 } 135 Console.WriteLine("第" + (i + 1) + "个同学的平均分为:" + sum / 5); 136 } 137 } 138 /// <summary> 139 /// 每科的平均分 140 /// </summary> 141 /// <param name="a"></param> 142 public void kepingjun(double[,] a) 143 { 144 double[,] fenshu = new double[10, 5]; 145 fenshu = a; 146 for (int i = 0; i < 5; i++) 147 { 148 double sum = 0; 149 for (int l = 0; l < 10; l++) 150 { 151 sum += fenshu[l, i]; 152 } 153 Console.WriteLine("第" + (i + 1) + "科的成绩为:" + sum / 10); 154 } 155 } 156 /// <summary> 157 /// 最高分最低分 158 /// </summary> 159 /// <param name="a"></param> 160 public void daxiao(double[,] a) 161 { 162 double[,] fenshu = new double[10, 5]; 163 fenshu = a; 164 double zhong; 165 double[] max = new double[5]; 166 double[] min = new double[5]; 167 for (int b = 0; b < 5; b++) 168 { 169 for (int l = 0; l < 10; l++) 170 { 171 for (int j = 0; j < l; j++) 172 { 173 if (fenshu[l, b] < fenshu[j, b]) 174 { 175 zhong = fenshu[l, b]; 176 fenshu[l, b] = fenshu[j, b]; 177 fenshu[j, b] = zhong; 178 } 179 } 180 } 181 max[b] = fenshu[9, b]; 182 min[b] = fenshu[0, b]; 183 } 184 for (int i = 0; i < 5; i++) 185 { 186 if (max[0] < max[i]) 187 { 188 max[0] = max[i]; 189 } 190 } 191 Console.WriteLine("最高分为:" + max[0]); 192 for (int i = 0; i < 5; i++) 193 { 194 if (min[0] > min[i]) 195 { 196 min[0] = min[i]; 197 } 198 } 199 Console.WriteLine("最低分为:" + min[0]); 200 } 201 /// <summary> 202 /// 求最高分最低分(简单方法) 203 /// </summary> 204 /// <param name="a"></param> 205 public void daxiao2(double[,] a) 206 { 207 double[,] fenshu = new double[10, 5]; 208 fenshu = a; 209 for (int i = 0; i < 10; i++) 210 { 211 for (int l = 0; l < 5; l++) 212 { 213 if (fenshu[0, 0] < fenshu[i, l]) 214 { 215 fenshu[0, 0] = fenshu[i, l]; 216 } 217 } 218 } 219 Console.WriteLine("最高分为:" + fenshu[0, 0]); 220 for (int i = 0; i < 10; i++) 221 { 222 for (int l = 0; l < 5; l++) 223 { 224 if (fenshu[0, 0] > fenshu[i, l]) 225 { 226 fenshu[0, 0] = fenshu[i, l]; 227 } 228 } 229 } 230 Console.WriteLine("最低分为:" + fenshu[0, 0]); 231 } 232 /// <summary> 233 /// 方差 234 /// </summary> 235 /// <param name="a"></param> 236 /// <returns></returns> 237 public double[] fangcha(double[,] a) 238 { 239 double[,] fenshu = new double[10, 5]; 240 double[] pingjun = new double[10]; 241 fenshu = a; 242 for (int i = 0; i < 10; i++) 243 { 244 double sum = 0; 245 for (int l = 0; l < 5; l++) 246 { 247 sum += fenshu[i, l]; 248 } 249 pingjun[i] = sum / 5; 250 } 251 return pingjun; 252 } 253 /// <summary> 254 /// 判断是否是闰年 255 /// </summary> 256 /// <param name="a"></param> 257 public void shijian(int a) 258 { 259 if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0) 260 { 261 Console.WriteLine("是闰年"); 262 } 263 else 264 { 265 Console.WriteLine("不是闰年"); 266 }//判断闰年 267 } 268 //public int a;//变量可以定义在外面,类似结构体。 269 static void Main(string[] args) 270 { 271 #region 练习 272 //Program pro = new Program(); 273 //pro.a = int.Parse ( Console.ReadLine()); 274 275 276 277 ////练习 找出100以内与7有关的数并打印 278 //Program hanshu = new Program(); 279 //hanshu.shuzi(); 280 281 282 283 ////练习 一个游戏,前20关是每一关自身的分数, 284 ////21-30关每一关是10分 285 ////31-40关,每一关是20分 286 ////41-49关,每一关是30分 287 ////50关,是100分 288 ////输入你现在闯到的关卡数,求你现在拥有的分数 289 //for (; ; ) 290 //{ 291 // Console.Write("请输入关卡数:"); 292 // int a = int.Parse(Console.ReadLine()); 293 // if (a >= 0 && a < 51) 294 // { 295 // Program hanshu = new Program(); 296 // Console.Write(hanshu.chuangguan(a)); 297 // break; 298 // } 299 // else 300 // { 301 // Console.WriteLine("输入错误,请重新输入!"); 302 // } 303 //} 304 305 306 307 ////打印99乘法表 308 //Program hanshu = new Program(); 309 //hanshu.chengfabiao(); 310 311 312 313 ////100以内奇数和 314 //Program hanshu = new Program(); 315 //Console.Write(hanshu.jishu()); 316 317 318 319 ////有1分钱,2分钱,5分钱硬币,要组合出6毛钱,有几种组合方式,怎样组合 320 //Program hanshu = new Program(); 321 //hanshu.qian(); 322 323 324 325 ////有一组函数:y = x (x<1);y = 2x -1 (1<=x<10); y = 3x-11 (x>=10)。 326 ////括号内是x的满足条件。 327 ////实现功能,随意输入一个x值,输出y的值。 328 //Console.Write("请输入X值:"); 329 //double a = double.Parse(Console.ReadLine()); 330 //Program hanshu = new Program(); 331 //Console.Write(hanshu.fangcheng(a)); 332 333 334 #endregion 335 #region 一个麻烦的练习 336 //输入十个学生5门课的成绩,分别用函数实现下列功能 337 //1.计算每个学生的平均分 338 //2.计算每门课的平均分 339 //3.找出所有50个分数中的最高分和最低分 340 //4.计算平均分方差(1/n(x1+……+x10)^2-(x1+……+x10/n)^2 xi为某一学生的平均分) 341 double[,] fenshu = new double[10, 5]; 342 343 for (int i = 0; i < 10; i++) 344 { 345 for (int l = 0; l < 5; l++) 346 { 347 Console.Write("请输入第" + (i + 1) + "个学生的第" + (l + 1) + "科成绩:"); 348 fenshu[i, l] = double.Parse(Console.ReadLine()); 349 } 350 } 351 Program hanshu = new Program(); 352 hanshu.renpingjun(fenshu);//每个学生的平均分 353 hanshu.kepingjun(fenshu);//每科的平均分 354 hanshu.daxiao(fenshu);//求最大最小分 355 hanshu.daxiao2(fenshu);//求最大最小简单方法 356 double[] fangcha = new double[10]; 357 fangcha = hanshu.fangcha(fenshu); 358 double sum = 0; 359 for (int i = 0; i < 10; i++) 360 { 361 sum += fangcha[i]; 362 } 363 double pingjunfangcha = (0.1 * sum * sum) - (sum / 10) * (sum / 10); 364 Console.WriteLine("平均分方差="+pingjunfangcha); 365 #endregion 366 367 ////1、输入年月日,看输入的日期是否正确 368 ////2、输出是今年是否是闰年(29天),输出日期 369 //// 闰年的判断普通年能被4整除且不能被100整除的为闰年,整百的年份能被400整除 370 ////3、输出是今年的第几天 371 //// 输入年,看年份是否正确,年(0-9999) 372 373 //for (; ; ) 374 //{ 375 // try 376 // { 377 // Console.Write("请输入日期:"); 378 // DateTime a = DateTime.Parse(Console.ReadLine()); 379 // int b = a.Year; 380 // Program hanshu = new Program(); 381 // hanshu.shijian(b); 382 // Console.WriteLine(a.DayOfYear);//输出第几天 383 // break; 384 // } 385 // catch 386 // { 387 // Console.WriteLine("您的输入有误!请重新输入!"); 388 // } 389 //} 390 391 392 393 Console.ReadLine(); 394 } 395 }
时间: 2024-10-11 14:49:18