Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Problem 7
- * Write a program to produce a table of numbers from 10 to 1, with their squares and cubes. Again,
- * your table must look professional!
- */
- namespace for_loop_07
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- //for loop
- Console.WriteLine("| x | x^2 | x^3 |");
- Console.WriteLine("| -- | --- | ---- |");
- for (int i = 10; i >= 1; i--)
- {
- Console.Write($"| {i,2} | {i * i,3} | {i * i * i,4} |");
- Console.WriteLine();
- }
- Console.Write("\n\n");
- //do while loop
- int start = 10, stop = 1;
- Console.WriteLine("| x | x^2 | x^3 |");
- Console.WriteLine("| -- | --- | ---- |");
- do
- {
- Console.Write($"| {start,2} | {start * start,3} | {start * start * start,4} |");
- Console.WriteLine();
- start--;
- } while (start >= stop);
- Console.Write("\n\n");
- //while loop
- start = 10;
- stop = 1;
- Console.WriteLine("| x | x^2 | x^3 |");
- Console.WriteLine("| -- | --- | ---- |");
- while (start >= stop)
- {
- Console.Write($"| {start,2} | {start * start,3} | {start * start * start,4} |");
- Console.WriteLine();
- start--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement