2
06/11/2024 6:57 pm
Topic starter
I need a program in C# which is calculating n to power m (or n^m). Please help me write it.
1 Answer
2
06/11/2024 6:58 pm
Use for loop:
using System; class ForLoop { static void Main() { Console.Write("n = "); int n = int.Parse(Console.ReadLine()); Console.Write("m = "); int m = int.Parse(Console.ReadLine()); decimal result = 1; for (int i = 0; i < m; i++) { result *= n; } Console.WriteLine("n^m = " + result); } }