heshm

using System;

Feb 13th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. if you need more http://bit.ly/31RTiBL
  2.  
  3.  
  4.  
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Collections.Generic;
  9.  
  10. namespace CSharp_Shell
  11. {
  12.  
  13. public static class Program
  14. {
  15. public static void Main()
  16. {
  17. PrintPowersOfN(4, 3);
  18. PrintPowersOfN(5, 6);
  19. PrintPowersOfN(-2, 8);
  20.  
  21. UserPrintPowersOfN();
  22. }
  23.  
  24. public static void UserPrintPowersOfN(){
  25. int baseInt = 1;
  26. int maxPower = 1;
  27. bool validBase = false;
  28. bool validPower = false;
  29.  
  30. while(!validBase){
  31. Console.Write("Enter base integer: ");
  32. validBase = int.TryParse(Console.ReadLine(), out baseInt);
  33. }
  34.  
  35. while(!validPower){
  36. Console.Write("\nEnter the maximum exponent: ");
  37. validPower = int.TryParse(Console.ReadLine(), out maxPower);
  38. }
  39.  
  40. Console.WriteLine();
  41. PrintPowersOfN(baseInt, maxPower);
  42. }
  43.  
  44. public static void PrintPowersOfN(int baseValue, int maxPower){
  45. for (int i = 0; i <= maxPower; i++){
  46. Console.Write((int)Math.Pow(baseValue, i) + " ");
  47. }
Add Comment
Please, Sign In to add comment