.Net基础篇_学习笔记_第六天_for循环语法_正序输出和倒序输出

for TAB  和 forr TAB

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 第六天_do_while循环
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             for (int i = 100; i <= 999; i++)
14             {
15 
16                 int bai = i/100;
17                 int shi = i%100/10;
18                 int ge = i%10;
19                 if (bai*bai*bai+shi*shi*shi+ge*ge*ge==i)
20                 {
21                     Console.WriteLine("水仙花数有{0}",i);
22                 }
23             }
24             Console.ReadKey();
25         }
26     }
27 }

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 第六天_do_while循环
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int sum = 0;
14             int n = 100;
15             for (int i = 1; i <=n; i+=2)
16             {
17                 sum += i;
18             }
19             Console.WriteLine(sum);
20             Console.ReadKey();
21         }
22     }

100以内所有偶数的和,所有奇数的和,所有整数的和......

posted @ 2017-07-20 13:57  MR_L先生  阅读(388)  评论(0编辑  收藏  举报