zoukankan      html  css  js  c++  java
  • 复习与循环语句练习

    复习

    //1.键盘键入三个数,找出来最大的数。

    //Console.Write("请输入一个数字:");
    //double a = double.Parse(Console.ReadLine());
    //Console.Write("请输入一个数字:");
    //double b = double.Parse(Console.ReadLine());
    //Console.Write("请输入一个数字:");
    //double c = double.Parse(Console.ReadLine());
    //double d;
    //if (a >= b)
    //{
    // d = a;
    //}
    //else
    //{
    // d = b;
    //}
    //if (d >= c)
    //{
    // Console.WriteLine("您输入的三个数中最大的是:" + d);
    //}
    //else
    //{
    // Console.WriteLine("您输入的三个数中最大的是:"+c);
    //}
    //Console.ReadLine();

    //2.“现在几点了?”键盘键入小时数,判断是上午还是下午。打印出来现在是上午几点还是下午几点
    //Console.Write("现在几点了");
    //int time = int.Parse(Console.ReadLine() );
    //if (time >= 1 && time <= 24)
    //{
    // if (time > 12)
    // {
    // Console.WriteLine("现在是下午" + (time - 12) + "点");
    // }
    // else
    // {
    // Console.WriteLine("现在是上午" + time + "点");
    // }
    //}
    //else
    //{
    // Console.WriteLine("您的输入有误!");
    //}
    //Console.ReadLine();


    //3.//输入一个小于等于100的整数,判断:
    ////是小于10的
    ////两位数
    ////是100
    //Console.WriteLine("请输入一个小于等于100的整数:");
    //int a = int.Parse(Console.ReadLine());
    //if (a < 10)
    //{
    // Console.WriteLine("这个数是小于10的数。");
    //}
    //else if (a >= 10 && a < 100)
    //{
    // Console.WriteLine("这个数是两位数。");
    //}
    //else
    //{
    // Console.WriteLine("这个数是100.");
    //}
    //Console.ReadLine();

    //4.//输入学生姓名,输入考试成绩 double
    ////若是100,【恭喜你***,满分通过!】
    ////若是大于等于80小于100,【**,你很优秀,继续保持!】
    ////若是大于等于60小于80,【**成绩良好】
    ////大于等于50小于60,【**就差一点点,下次一定要至少及格!】
    //Console.WriteLine("请输入您的姓名:");
    //string name = Console.ReadLine();
    //Console.WriteLine("请输入您的成绩:");
    //double fen = double.Parse(Console .ReadLine ());
    //if (fen ==100)
    //{
    // Console.WriteLine("恭喜你"+name +",满分通过");
    //}
    //else if(fen>=80&&fen<100)
    //{
    // Console.WriteLine(name + "你很优秀,继续保持");
    //}
    //else if(fen>=60&&fen<80)
    //{
    // Console.WriteLine(name + ",成绩良好");
    //}
    //else if(fen <60&&fen>=50)
    //{
    // Console.WriteLine(name+",就差一点点,下次一定要至少及格!");
    //}


    //else if (fen >= 0 && fen < 50)
    //{
    // Console.WriteLine(name + ",你是笨蛋么?");
    //}
    //else
    //{
    // Console.WriteLine("请输入正确的分数");
    //}
    //Console.ReadLine();

    //5.输入年份,判断是否是闰年。
    //Console.Write("请输入年份");
    //int year=int.Parse(Console.ReadLine());
    //if(year>0&&year<=9999)
    // if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    // {
    // Console.WriteLine("您输入的年份是闰年");
    // }
    // else
    // {
    // Console.WriteLine("您输入的年份不是闰年");
    // }
    //else
    //{
    //Console.WriteLine("您输入有误");
    //}
    //Console.ReadLine();


    //6.有一组函数:y = x (x<1);y = 2x -1 (1<=x<10); y = 3x-11 (x>=10)。
    //括号内是x的满足条件。
    //实现功能,随意输入一个x值,输出y的值。
    //Console.WriteLine("请输入x=");
    //double x = double.Parse(Console.ReadLine());
    //if (x < 1)
    //{
    // double y = x;
    // Console.WriteLine("y=" + y);
    //}
    //else if (x >= 1 && x < 10)
    //{
    // double y = 2 * x - 1;
    // Console.WriteLine("y=" + y);
    //}
    //else
    //{
    // double y = 3 * x - 1;
    // Console.WriteLine("y=" + y);
    //}
    //Console.ReadLine();

    ////7.相亲过程:你有房子么?你有钱么?你有能力么?
    ////【结婚吧】【先买房子在结婚】【先赚钱再买房子再结婚】都没有【拜拜~~】
    ////利用if嵌套做相亲过程
    //Console.Write("你有房子么?");
    //string a = Console.ReadLine();
    //if (a == "有")
    //{
    // Console.Write("结婚吧");
    //}
    //else
    //{
    // Console.Write("你有钱么?");
    // string b = Console.ReadLine();
    // if (b == "有")
    // {
    // Console.Write("先买房子再结婚");
    // }
    // else
    // {
    // Console.Write("你有能力么?");
    // string c = Console.ReadLine();
    // if (c == "有")
    // {
    // Console.Write("先赚钱再买房子再结婚");
    // }
    // else
    // {
    // Console.Write("拜拜~~");
    // }
    // }
    //}
    //Console.ReadLine();


    //8.输入年月日,看看格式是否正确
    //Console.Write("请输入年份:");
    //int y = int.Parse(Console.ReadLine());
    //if (y >= 0 && y <= 9999)
    //{
    // Console.Write("请输入月份:");
    // int m = int.Parse(Console.ReadLine());
    // if (m >= 1 && m <= 12)
    // {
    // Console.Write("请输入日:");
    // int d = int.Parse(Console.ReadLine());
    // if(d>=0&&d<=31)
    // {
    // if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
    // {
    // Console.WriteLine("你输入的日期格式正确!");
    // }
    // else if(m==4||m==6||m==9||m==11)
    // {
    // if (d <= 30)
    // {
    // Console.WriteLine("您输入的日期格式正确!");
    // }
    // else
    // {
    // Console.WriteLine("您输入的日期格式不正确!");
    // }
    // }
    // else
    // {
    // if(d<=29)
    // {
    // if(y%4==0&&y%100!=0||y%400==0)
    // {
    // Console.WriteLine("您输入的日期格式正确!");
    // }
    // else
    // {
    // Console.WriteLine("您输入的日期格式错误!");
    // }

    // }
    // else
    // {
    // Console.WriteLine("您输入的日期格式错误!");
    // }
    // }


    // }
    // else
    // {
    // Console.WriteLine("您输入的日有误!");
    // }

    // }
    // else
    // {
    // Console.WriteLine("您输入的月份有误!");
    // }
    //}
    // else
    //{
    // Console.WriteLine("您输入的年份有误!");
    //}

    //Console.ReadLine();


    //9.方程ax2+bx+c=0;一元二次方程。求根
    //△=b2-4ac;若△<0方程无实根
    //若△>0,方程有两个不相同的实根x1 x2
    //若△=0,方程有两个相同的实根
    //Console.Write("方程ax^2+bx+c=0,求根");
    //Console.Write("输入a");
    //double a = double.Parse(Console.ReadLine());
    //if (a != 0)
    //{
    // Console.WriteLine("输入b");
    // double b = double.Parse(Console.ReadLine());
    // Console.WriteLine("输入c");
    // double c = double.Parse(Console.ReadLine());
    // double de = b * b - 4 * a * c;
    // if (de > 0) {
    // double x1=(-b+Math.Sqrt(de))/(2*a);
    // double x2 = (-b - Math.Sqrt(de)) / (2 * a);
    // Console.WriteLine("方程有两个不同的实数根x1={0},x2={1}",x1,x2);

    // }
    // else if (de == 0)
    // {
    // double x1 = (-b + Math.Sqrt(de)) / (2 * a);
    // Console.WriteLine("方程有两个相同的实数根x1=x2={0}", x1);
    // }
    // else {
    // Console.WriteLine("方程没有实数根");
    // }
    //}
    //else {
    // Console.WriteLine("此方程不是一元二次方程");
    //}
    //Console.ReadLine();


    //10.标准体重:
    //男士体重=身高-100±3
    //女士体重=身高-110±3

    //Console.Write("请输入您的性别");
    //string a = Console.ReadLine();
    //Console.Write("请输入您的体重");
    //double b = double.Parse(Console.ReadLine());
    //Console.Write("请输入您的身高");
    //double c = double.Parse(Console.ReadLine());
    //if (a == "男生")
    //{
    //double d =b-c+100;
    // if(d>=-3&&d<=3)
    // {
    // Console.WriteLine("您是标准体重");
    // }
    // else if(d>3)
    // {
    // Console.WriteLine("您的体重偏高");
    // }
    // else
    // {
    // Console.WriteLine("您的体重偏瘦");
    // }
    //}
    // else if(a=="女生")
    // {
    // double e=b-c+110;
    // if(e>=-3&&e<=3)
    // {
    // Console.WriteLine("您是标准体重");
    // }
    // else if(e>3)
    // {
    // Console.WriteLine("您的体重偏高");
    // }
    // else
    // {
    // Console.WriteLine("您的体重偏瘦");
    // }


    // }


    //else
    //{
    //Console.WriteLine("您的输入有误");
    //}
    //Console.ReadLine();


    //11.键盘键入三个数,按照从大到小的顺序打印出来


    //Console.Write("请输入a:");
    //double a = double.Parse(Console.ReadLine());
    //Console.Write("请输入b:");
    //double b = double.Parse(Console.ReadLine());
    //Console.Write("请输入c:");
    //double c = double.Parse(Console.ReadLine());
    //if (a > b)
    //{
    // if (a > c)
    // {
    // if (b > c)
    // {
    // Console.WriteLine(a + "," + b + "," + c);
    // }
    // else
    // {
    // Console.WriteLine(a + "," + c + "," + b);
    // }
    // }
    // else
    // {
    // Console.WriteLine(c + "," + a + ","+b);
    // }
    //}
    //else//a=<b
    //{
    // if (a > c)
    // {
    // Console.WriteLine(b + "," + a + "," + c);
    // }
    // else
    // {
    // if (b > c)
    // {
    // Console.WriteLine(b + "," + c+ "," + a);
    // }
    // else
    // {
    // Console.WriteLine(c + "," + b + "," + a);
    // }
    // }
    //}
    //Console.ReadLine();

    //语句的分类:顺序,分支,循环
    //循环语句
    //for (int i=1;i<=10 ;i++ )
    //{
    // Console.WriteLine("你好");
    //}
    //Console.ReadLine();

    //死循环
    //for (; ; )
    //{
    // Console.WriteLine("Hello");
    //}


    //输入一个整数,计算从1加到这个数的结果
    //Console.Write("请输入一个正整数:");
    //int a = int.Parse(Console.ReadLine());
    //int sum = 0;
    //for (int i = 1; i <= a; i++)
    //{
    // sum += i;//sum=sum+i;
    //}

    //Console.WriteLine(sum);
    //Console.ReadLine();

    //输入一个正整数,求阶乘
    //Console.Write("请输入一个正整数:");
    //int a = int.Parse(Console.ReadLine());
    //int sum = 1;
    //for (int i = 1; i <= a; i++)
    //{
    // sum *= i;//sum=sum*i;
    //}

    //Console.WriteLine(sum);
    //Console.ReadLine();

    //输入一个正整数,求阶乘的和1!+2!+...+n!
    //Console.Write("请输入一个正整数:");
    //int a = int.Parse(Console.ReadLine());
    //int sum = 1;
    //int sum1 = 0;
    //for (int i = 1; i <= a; i++)
    //{
    // sum *= i;//sum=sum*i;
    // if (i == 4)//不想要4的
    // {
    // continue;//终止本次循环,继续下次循环
    // }
    // sum1 += sum;
    //}

    //Console.WriteLine(sum1);
    //Console.ReadLine();

    //一个游戏,前20关是每一关自身的分数,
    //21-30关每一关是10分
    //31-40关,每一关是20分
    //41-49关,每一关是30分
    //50关,是100分
    //输入你现在闯到的关卡数,求你现在拥有的分数
    //两种做法:if嵌套for for嵌套if
    //Console.Write("请输入您现在闯到的关卡数:");
    //int guan = int.Parse(Console.ReadLine());
    //if (guan >= 1 && guan <= 50)
    //{
    // int sum = 0;
    // if (guan <= 20)
    // {
    // for (int i = 1; i <= guan; i++)
    // {
    // sum += i;
    // }
    // }
    // else if (guan <= 30)
    // {
    // for (int i = 1; i <= 20; i++)
    // {
    // sum += i;
    // }
    // for (int i = 21; i <= guan; i++)
    // {
    // sum += 10;
    // }
    // }
    // else if (guan <= 40)
    // {
    // for (int i = 1; i <= 20; i++)
    // {
    // sum += i;
    // }
    // for (int i = 21; i <= 30; i++)
    // {
    // sum += 10;
    // }
    // for (int i = 31; i <= guan; i++)
    // {
    // sum += 20;
    // }
    // }
    // else if (guan <= 49)
    // {
    // for (int i = 1; i <= 20; i++)
    // {
    // sum += i;
    // }
    // for (int i = 21; i <= 30; i++)
    // {
    // sum += 10;
    // }
    // for (int i = 31; i <= 40; i++)
    // {
    // sum += 20;
    // }
    // for (int i = 41; i <= guan; i++)
    // {
    // sum += 30;
    // }
    // }
    // else//50关
    // {
    // for (int i = 1; i <= 20; i++)
    // {
    // sum += i;
    // }
    // for (int i = 21; i <= 30; i++)
    // {
    // sum += 10;
    // }
    // for (int i = 31; i <= 40; i++)
    // {
    // sum += 20;
    // }
    // for (int i = 41; i <= 49; i++)
    // {
    // sum += 30;
    // }
    // sum += 100;
    // }
    // Console.WriteLine(sum);
    //}
    //else
    //{
    // Console.WriteLine("输入有误!");
    //}
    //Console.ReadLine();

    //Console.Write("请输入您现在闯到的关卡数:");
    //int guan = int.Parse(Console.ReadLine());
    //if (guan <= 50 && guan >= 1)
    //{
    // int sum = 0;
    // for (int i = 1; i <= guan; i++)
    // {
    // if (i <= 20)
    // {
    // sum += i;
    // }
    // else if (i <= 30)
    // {
    // sum += 10;
    // }
    // else if (i <= 40)
    // {
    // sum += 20;
    // }
    // else if (i <= 49)
    // {
    // sum += 30;
    // }
    // else
    // {
    // sum += 100;
    // }
    // }
    // Console.WriteLine(sum);
    //}
    //else
    //{
    // Console.WriteLine("输入有误!");
    //}
    //Console.ReadLine();


    //找出100以内与7有关的数并打印、
    //(1).从1找到100
    //(2).找出与7有关的数
    // 个位数是7 a%10==7
    // 十位数是7 a/10 ==7
    // 能被7整除 a%7 ==0
    for (int i = 1; i <= 100; i++)
    {
    if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
    {
    Console.Write(i+" ");
    }
    }
    Console.ReadLine();

  • 相关阅读:
    “花田喜事” 婚庆网站策划
    discuz 模块模板标签说明 DIY模块模板语法详解
    discuz x2.5 广告位开发学习(第二步:制作)
    DiscuzX2.5完整目录结构【模板目录template】
    Webservice 安全性访问
    X2.5 怎么关闭个人空间
    心中有佛,看人即佛;心中有屎,看人即屎
    discuz x2.5 广告位开发学习(第一步:摸索)
    UVA 128 Software CRC
    UVA 10791 Minimum Sum LCM
  • 原文地址:https://www.cnblogs.com/yx1314520/p/5698866.html
Copyright © 2011-2022 走看看