编程实践6-5
编程实践6-5
using System; namespace sj_6_5 { class Program { static void Main(string[] args) { int a, n; Console.Write("请输入A的值:\n"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入N的值:\n"); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(js(a, n)); Console.ReadKey(); } public static int js(int x, int y) { int c; string d; c = x; d = "11"; for (int i = 0; i < y - 1; i++) { c = c + x * Convert.ToInt32(d); d = d + "1"; } return c; } } }
.版本2
using System; namespace sj_6_5 { class Program { static void Main(string[] args) { int a, n; Console.Write("请输入A的值:\n"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入N的值:\n"); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(js(a, n)); Console.ReadKey(); } public static int js(int x, int y) { int a = 0,c = 0; for (int i = 0; i < y; i++) { a = a * 10 + x; c = c + a; } return c; } } }