Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a in C#.
Write a C# program that accepts an integer (n) and computes the value of n+nn+nnn.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | class Program { static void Main(string[] args) { Console.Write("Enter Digit :"); int digit = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter a number :"); string num = Console.ReadLine(); int sum = 0; for (int i = 1; i <= digit; i++) { string number = ""; for (int j = 0; j < i; j++) { number = number + num; } Console.WriteLine(number); sum += Convert.ToInt32(number); } Console.WriteLine("_______________+"); Console.WriteLine(sum); Console.ReadKey(); } } |
Output: