24665人加入学习
(72人评价)
C#编程-第一季-编程基础-宇宙最简单2021最新版

制作完成于2021年10月10日,使用Visual Studio 2019

价格 免费

不知道为什么正确了

 

 

 

  一个整数除以100的结果还是整数,除以100.0可以得到小数

[展开全文]
using System;

namespace _019_while循环_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int number = 80000;
            //int year = 2006;
            //while (number < 200000)
            //{
            //    number = (int)(number * 1.25);//增加了一年
            //    year++;
            //}
            //Console.WriteLine(year);


            //int n = Convert.ToInt32(Console.ReadLine());
            //int i = 1;
            //int sum = 0;
            //while (i < n + 1)
            //{
            //    //int year = Convert.ToInt32(Console.ReadLine());
            //    //sum += year;
            //    sum += Convert.ToInt32(Console.ReadLine());
            //    i++;
            //}
            //double ave = 1.0 * sum / n;
            //// 4.5342 100 int 453
            //ave = ((int)(ave * 100)) / 100.0;
            //Console.WriteLine(ave);


            //Console.WriteLine(1);
            //Console.Write(2);
            //Console.Write(3);
            //Console.WriteLine(4);
            ////1
            ////234
            ////


            int n = Convert.ToInt32(Console.ReadLine());
            int i = 1;
            while (i < n + 1)
            {
                Console.Write(i + " ");
                i++;
            }

        }
    }
}

 

[展开全文]

//输入一个数n,输出1-n

int n=Convert.Toint32(Console.Readline());

int i=1;

while (i<n+1)

{

Console.Write(i+"");

 

[展开全文]

ctrl+k+c=注释

ctrl+k+u=解除注释

 

[展开全文]
static void test02()
        {
            int student = 80000;
            int year = 2006;
            while (student<200000)
            {
                student =(int )(student* 1.25);
                year++;
                Console.WriteLine("student="+student);
            }
            Console.WriteLine("year="+year);           
        }
        static void test03()
        {
            Console.WriteLine("请输入学生个数:");
            int student = Convert.ToInt32(Console.ReadLine());
            double sum = 0;
            for (int i = 1; i <= student; i++)
            {
                Console.WriteLine("请输入{0}号学生的年龄:", i);
                double old = Convert.ToInt32(Console.ReadLine());
                sum += old;
            }
            double averageValue=sum/student;
            Console.WriteLine("平均年龄是:{0}",averageValue);
        }
        static void test04()
        {
            Console.WriteLine("请输入整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <=n; i++)
            {
                Console.Write(" "+i);
            }
        }

 

[展开全文]

1.int ave

ave变为double类型

(int)(ave*100)/100

2.Write:输出(不换行)

3.WriteLine:输出 换行

4.空格隔开:Console.Write(n+" ”)

[展开全文]

第五十四课  编程题while循环

1. 班上有若干名学生,输入学生的个数,然后输入每一个学生的年龄,计算出来平均年龄,保留到小数点后两位,输出平均年龄。

int mub=Convert.ToInt32(Console.ReadLine());
int temp = 0;
double count = 0;
while (temp< mub)
{
    int a = Convert.ToInt32(Console.ReadLine());
    count += a;
    temp++;
}
double pj = 1.0*count /mub;
double d = ((int)(pj * 100)) / 100.0;
Console.WriteLine("学生的平均年龄为:"+d);

可修改为老师的方法:

int mub=Convert.ToInt32(Console.ReadLine());
int temp = 0;
double count = 0;
while (temp< mub)
{
    int a = Convert.ToInt32(Console.ReadLine());
    count += a;
    temp++;
}
double pj = 1.0*count /mub;
pj = ((int)(pj * 100)) / 100.0;
Console.WriteLine("平均年龄为:"+pj);

2. Console.WrtieLine();

表示输出并换行,是先输出再换行。

例如:

Console.Wrtie(1);

Console.Wrtie(2);

Console.WrtieLine(3);

Console.Wrtie(4);

输出结果为:

123

4

3再同一行,表示WriteLine功能是先输出并换行。

3.单独使用Console.WriteLine();

只起到换行的作用,不输出任何值。

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(118)
图文(1)