C# Program to Calculate Power of Three

This is a C# Program to calculate power of three.

Problem Description

This C# Program Calculates Power of Three.

Problem Solution

Here the power value of the given number is found.

Program/Source Code

Here is source code of the C# Program to Calculate Power of Three. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Calculate Power of Three
 */
 
 
using System;
 
class Program
{
    static void Main(string[] args)
    {
        new GeneratePowers().RaiseToPower
           (5,    // 4 values per table
            3);
        Console.ReadLine();// power to raise each value
    }
}
 
public class GeneratePowers
{
    public void RaiseToPower(int maxIterations, int power)
    {
        Console.WriteLine("{0,8}{1,16}",
            "Number", "Power of " + power);
        for (int i = 1; i <= maxIterations; ++i)
        {
            Console.Write("{0,5}{1,15}\n", i,
               Math.Pow(i, power));
        }
    }
 }
Program Explanation

In this C# program, library function defined in <math.h> header file is used. In RaiseToPower procedure using for loop compute the power value of the given number and print the values.

advertisement
advertisement
Runtime Test Cases
 
  Number      Power of 3
    1              1
    2              8
    3             27
    4             64
    5            125

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.