赞
踩
编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //让用户输入整数,如果=0,就结束 不等于0 就继续 最后求所有整数和
-
- int n,sum=0;
- Console.WriteLine("请输入一个整数n:");
- n = Convert.ToInt32(Console.ReadLine());
-
- do
- {
- Console.WriteLine("请继续输入一个整数n:");
- sum += n;
- n = Convert.ToInt32(Console.ReadLine());
-
- }
- while (n !=0);
-
- Console.WriteLine("总和为"+sum);
- }
- }
- }

代码运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //一个球从某一高度落下来,每次落地后反跳回原来高度的一半,再落下。编程计算球第10次反弹多高?在第10次落地时,共经过多少米?
- // 输入球的初始高度,输出反弹多高,和经过了多少米。
-
- Console.WriteLine("请输入球的初始高度:");
- float ch= Convert .ToSingle (Console.ReadLine());
- float jh = ch*2,sum=ch;
- for(int i=0;i<10;i++)
- {
- ch /= 2;
-
- }
-
- for(int k=0;k<9;k++)
- {
- jh /= 2;
- sum += jh;
- }
-
- Console.WriteLine("第十次后,经过{0}米,反弹{1}米", sum, ch);
- Console.ReadKey(true);
- }
- }
- }

程序运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //输入一个整数a,和一个正整数n,计算乘方a的n次方
- Console.WriteLine("请输入a以及n次方的n");
- int a = Convert.ToInt32(Console.ReadLine());
- int n = Convert.ToInt32(Console.ReadLine());
- int b=1;
- if(n<=0)
- {
- Console.WriteLine("n必须为正整数!");
- }
- else
- {
- for(int i=1;i<=n;i++)
- {
- b = b * a;
- }
- Console.WriteLine("结果为" + b);
- }
- }
- }
- }

程序运行结果如下:



编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //输入整数n,输出n的阶乘
- Console.WriteLine("请输入整数n");
- int n = Convert.ToInt32(Console.ReadLine());
- int sum=1;
- for(int i=1;i<=n;i++)
- {
- sum *= i;
- }
- Console.WriteLine("结果是:" + sum);
- }
- }
- }

程序运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //输入整数q,n 按照题目要求 :n>=0
- Console.WriteLine("请输入整数q和n");
- int q = Convert.ToInt32(Console.ReadLine());
- int n = Convert.ToInt32(Console.ReadLine());
- int sum=1;
- int b = 1;
- if(n==0)
- {
- sum = 1;
- }
- else
- {
- for (int i = 1; i <= n; i++)
- {
- b = b * q;
- sum += b;
- }
- }
-
- Console.WriteLine("结果是:" + sum);
- }
- }
- }

程序运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
-
- Console.WriteLine("请输入整数k,1<=k<=15");
- int k = Convert.ToInt32(Console.ReadLine());
- double sn = 0;
- int n = 1;
- while (sn<=k)
- {
- sn += 1.0 / n;
- n++;
- }
- n -= 1;
- Console.WriteLine("结果是:" + n);
- }
- }
- }

程序运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- //有x亿人口 每年增加0.1% n年后会有多少人
- Console.WriteLine("请输入初始人口:x,要求地年份:n");
- double x = Convert.ToDouble(Console.ReadLine());
- int n = Convert.ToInt32(Console.ReadLine());
- double peo = 0;
- for (int i = 1; i <= n; i++)
- {
- peo = x * (1 + 0.001);
- }
- Console .WriteLine ("结果为:"+peo);
- }
- }
- }

程序运行结果如下:


编写代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace _1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int r = Convert.ToInt32(Console.ReadLine());
- int m = Convert.ToInt32(Console.ReadLine());
- int y = Convert.ToInt32(Console.ReadLine());
-
- for (int i=0;i<y;i++)
- {
- m =(int ) (m * ((r / 100.0) + 1));
- }
- Console.WriteLine("结果为:" + m);
- }
- }
- }

程序运行结果如下:

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。