C#练习题 -- 求1-100中和7有关的数

举报
陈言必行 发表于 2021/08/13 23:07:35 2021/08/13
【摘要】 分析:有三种情况一种是7的倍数,一种是个位是7,一种是十位有7,,但是这三种情况有重复出现,所以判断条件有添加即可,,,   using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tas...
分析:有三种情况一种是7的倍数,一种是个位是7,一种是十位有7,,但是这三种情况有重复出现,所以判断条件有添加即可,,,
 

    
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace fengqidayin
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             for (int i = 1; i < 101; i++)
  13.             {
  14.                 if (i % 7 == 0)
  15.                 {
  16.                     System.Console.WriteLine(i);
  17.                 }
  18.                 int a = i % 10;
  19.                 if (a == 7 && i % 7 != 0)
  20.                 {
  21.                     System.Console.WriteLine(i);
  22.                 }
  23.                 int b = i / 10 % 10;
  24.                 if (b == 7 && i % 7 != 0 && i % 10!=7 )
  25.                 {
  26.                     System.Console.WriteLine(i);
  27.                 }
  28.             }
  29.             System.Console.ReadLine();
  30.         }
  31.     }
  32. }

 

 
简化:
 

     
  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.         for (int i = 1; i <= 100; i++)
  6.         {
  7.               if (i % 7 == 0  ||  i % 10==7 ||  i /10 ==7)
  8.           {             
  9.                   System.Console.WriteLine(i);
  10.               }
  11.           }
  12.         System.Console.ReadLine();
  13.       }
  14. }

 

文章来源: czhenya.blog.csdn.net,作者:陈言必行,版权归原作者所有,如需转载,请联系作者。

原文链接:czhenya.blog.csdn.net/article/details/76091351

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。