Venciity

[Jumpstart C#] loops demo - N^M

Jan 24th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.38 KB | None | 0 0
  1. using System;
  2.  
  3. class Power
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("n = ");
  8.         int n = Int32.Parse(Console.ReadLine());
  9.         Console.Write("m = ");
  10.         int m = Int32.Parse(Console.ReadLine());
  11.  
  12.         decimal result = 1;
  13.        
  14.         for(int i = 0; i < m; i++)
  15.         {
  16.             result *= n;
  17.         }
  18.  
  19.         Console.WriteLine("n to the power of m is {0}", result);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment