Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if you need more http://bit.ly/31RTiBL
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public static class Program
- {
- public static void Main()
- {
- PrintPowersOfN(4, 3);
- PrintPowersOfN(5, 6);
- PrintPowersOfN(-2, 8);
- UserPrintPowersOfN();
- }
- public static void UserPrintPowersOfN(){
- int baseInt = 1;
- int maxPower = 1;
- bool validBase = false;
- bool validPower = false;
- while(!validBase){
- Console.Write("Enter base integer: ");
- validBase = int.TryParse(Console.ReadLine(), out baseInt);
- }
- while(!validPower){
- Console.Write("\nEnter the maximum exponent: ");
- validPower = int.TryParse(Console.ReadLine(), out maxPower);
- }
- Console.WriteLine();
- PrintPowersOfN(baseInt, maxPower);
- }
- public static void PrintPowersOfN(int baseValue, int maxPower){
- for (int i = 0; i <= maxPower; i++){
- Console.Write((int)Math.Pow(baseValue, i) + " ");
- }
Add Comment
Please, Sign In to add comment