Advertisement
Cnvmendoza

x, x^2, x^3

Mar 14th, 2024 (edited)
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | Source Code | 0 0
  1. /* Problem 7
  2.  * Write a program to produce a table of numbers from 10 to 1, with their squares and cubes. Again,
  3.  * your table must look professional!
  4.  */
  5. namespace for_loop_07
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //for loop
  12.             Console.WriteLine("|  x | x^2 |  x^3 |");
  13.             Console.WriteLine("| -- | --- | ---- |");
  14.             for (int i = 10; i >= 1; i--)
  15.             {
  16.                 Console.Write($"| {i,2} | {i * i,3} | {i * i * i,4} |");
  17.                 Console.WriteLine();
  18.             }
  19.  
  20.             Console.Write("\n\n");
  21.             //do while loop
  22.             int start = 10, stop = 1;
  23.             Console.WriteLine("|  x | x^2 |  x^3 |");
  24.             Console.WriteLine("| -- | --- | ---- |");
  25.             do
  26.             {
  27.                 Console.Write($"| {start,2} | {start * start,3} | {start * start * start,4} |");
  28.                 Console.WriteLine();
  29.                 start--;
  30.             } while (start >= stop);
  31.  
  32.             Console.Write("\n\n");
  33.             //while loop
  34.             start = 10;
  35.             stop = 1;
  36.             Console.WriteLine("|  x | x^2 |  x^3 |");
  37.             Console.WriteLine("| -- | --- | ---- |");
  38.             while (start >= stop)
  39.             {
  40.                 Console.Write($"| {start,2} | {start * start,3} | {start * start * start,4} |");
  41.                 Console.WriteLine();
  42.                 start--;
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement