3.24
Eg1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg1
{
class Program
{
static void Main(string[] args)
{
string userName;
//Console.WriteLine();在命令行打印输出则换行
// Console.WriteLine("请输入你的名字:");
Console.Write("请输入你的名字");//不换行
//将命令行中输入的字符赋值给userName
userName = Console.ReadLine();
Console.WriteLine("你的名字{0}", userName);
Console.ReadKey();
}
}
}
Eg2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg2
{
class Program
{
static void Main(string[] args)
{
//一堆数字为 1.1.2.3.5.8.13.21从中找出规律,输入第n个,可求出第n数字为多少
//Boolean bl = true;
//while (bl)
//{
// Console.WriteLine("请输入数字:");
// string number = Console.ReadLine();
// int a = int.Parse(number);
// int b = 1;
// int c = 1;
// int Res = 0;
// if (a == 1 || a == 2)
// {
// Res = 1;
// }
// else
// {
// for (int i = 0; i < a- 1; i++)
// {
// Res = b + c;
// c = b;
// b = Res;
// }
// }
// Console.WriteLine(Res.ToString());
// Console.ReadKey();
//}
Boolean bl = true;
while (bl)
{
Console.WriteLine("请输入数字:");
string number =Console.ReadLine();
int a = int.Parse(number);
int b = 1;
int c = 1;
int Res = 0;
if (a == 1 || a == 2)
{
Res = 1;
}
else
{
int[] arr = new int[a + 1];
arr[0] = 0;
arr[1] = 1;
for (int i = 2; i <= a;i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
Res = arr[i];
}
}
Console.WriteLine(Res.ToString());
Console.ReadKey();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg3
{
class Program
{
static void Main(string[] args)
{
//判断101-200之间有多少素数,并输出所有素数
//for (int i = 101; i <= 200; i++) {
// if (i % 2 == 0) {
// Console.WriteLine("这是素数{0}",i);
// }
//}
//Console.ReadKey();
//int y=101;
//while (y <= 200) {
// if (y % 2 == 0) {
// Console.WriteLine("这是素数{0}",y);
// }
// y++;
//}
//Console.ReadKey();
int[] Ayy = new int[100];
for (int i = 101; i <= 200; i++) {
Ayy[i - 101] = i;
}
foreach (int x in Ayy) {
if (x % 2 == 0) {
Console.WriteLine("这是素数{0}",x);
}
}
Console.ReadKey();
}
}
}
Eg1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg1
{
class Program
{
static void Main(string[] args)
{
string userName;
//Console.WriteLine();在命令行打印输出则换行
// Console.WriteLine("请输入你的名字:");
Console.Write("请输入你的名字");//不换行
//将命令行中输入的字符赋值给userName
userName = Console.ReadLine();
Console.WriteLine("你的名字{0}", userName);
Console.ReadKey();
}
}
}
Eg2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg2
{
class Program
{
static void Main(string[] args)
{
//一堆数字为 1.1.2.3.5.8.13.21从中找出规律,输入第n个,可求出第n数字为多少
//Boolean bl = true;
//while (bl)
//{
// Console.WriteLine("请输入数字:");
// string number = Console.ReadLine();
// int a = int.Parse(number);
// int b = 1;
// int c = 1;
// int Res = 0;
// if (a == 1 || a == 2)
// {
// Res = 1;
// }
// else
// {
// for (int i = 0; i < a- 1; i++)
// {
// Res = b + c;
// c = b;
// b = Res;
// }
// }
// Console.WriteLine(Res.ToString());
// Console.ReadKey();
//}
Boolean bl = true;
while (bl)
{
Console.WriteLine("请输入数字:");
string number =Console.ReadLine();
int a = int.Parse(number);
int b = 1;
int c = 1;
int Res = 0;
if (a == 1 || a == 2)
{
Res = 1;
}
else
{
int[] arr = new int[a + 1];
arr[0] = 0;
arr[1] = 1;
for (int i = 2; i <= a;i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
Res = arr[i];
}
}
Console.WriteLine(Res.ToString());
Console.ReadKey();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Eg3
{
class Program
{
static void Main(string[] args)
{
//判断101-200之间有多少素数,并输出所有素数
//for (int i = 101; i <= 200; i++) {
// if (i % 2 == 0) {
// Console.WriteLine("这是素数{0}",i);
// }
//}
//Console.ReadKey();
//int y=101;
//while (y <= 200) {
// if (y % 2 == 0) {
// Console.WriteLine("这是素数{0}",y);
// }
// y++;
//}
//Console.ReadKey();
int[] Ayy = new int[100];
for (int i = 101; i <= 200; i++) {
Ayy[i - 101] = i;
}
foreach (int x in Ayy) {
if (x % 2 == 0) {
Console.WriteLine("这是素数{0}",x);
}
}
Console.ReadKey();
}
}
}
