Question

In: Computer Science

In the Main method add the code that counts by 1, 2, 3, 4, and 5 – see output below Use a nested for loop to implement the series of numbers C# Syntax:

code in C#

How to count by n:

 

In the Main method add the code that counts by 1, 2, 3, 4, and 5 – see output below Use a nested for loop to implement the series of numbers C# Syntax:

 The C# syntax for variable declarations, and if, if-else, while, and for statements is identical to Java

 

C# console output:

 Console.Write("{0,2} ", number); // in this context number is an integer variable writes a number right-aligned in a column of width 2 followed by a blank  Console.Write("*"); // prints a *  Console.WriteLine(); // advances to the next line

Output:

1

2 4

3 6 9

4 8 12 16

5 10 15 20 25

Solutions

Expert Solution

C# code:

using System;
class Program {
    static void Main() {
        //looping from 1 to 5
        for(int i=1;i<=5;i++){
            //looping from 1 to i
            for(int j=1;j<=i;j++)
                //printing i*j
                Console.Write((i*j)+" ");
            //printing newline
            Console.WriteLine();
        }
    }
}


Screenshot:


Output:


Related Solutions

I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 +...
I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 + ...(n-1)*n. (Only nested loops) 2.Fibonacci numbers.
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5]...
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5] newVec= [] for i=vec if i>5 new vec=[newvec, i] end end end
A.) 1. Write a loop that prints the numbers 1-25i.e. B.) 1 2 3 4... 252....
A.) 1. Write a loop that prints the numbers 1-25i.e. B.) 1 2 3 4... 252. Write a loop that prints all the even numbers between 1 and 50i.e. 2 4 6 8... 483. C.) Create a list of the following fruits: oranges, apples, grapes and mangos and cherries. Write a loop that prints out every other fruit starting with oranges.i.e. oranges grapes and cherries.
Question 1 Refer to the operations below: Add (10 + 5) Add (4+8) Add (7*2) Add...
Question 1 Refer to the operations below: Add (10 + 5) Add (4+8) Add (7*2) Add (90 – 3) Print list Print peek Remove an item from the list Print list 1.1 Implement the operations above into a Queue structure called q1. 1.2 Implement the operations above into a Stack structure called s1. Name your program Question1_1 for the queue structure and Question1_2 for the stack structure JAVA Language to be used. Please give step by step explanation on how...
Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4,...
Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4, 3
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally,...
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally, it can be expressed as: fib0 = 0 fib1 = 1 fibn = fibn-1 + fibn-2 Write a multithreaded C++ program that generates the Fibonacci series using the pthread library. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program will generate. The program will then create a separate thread that will...
Consider the set of integers A = {1, 2, 3, 4, 5}. Pairs of numbers are...
Consider the set of integers A = {1, 2, 3, 4, 5}. Pairs of numbers are constructed where each number of the pair comes from set A. Construct the sampling distribution of sample ranges. Apply the Empirical Rule to this distribution.
1. What will print? int[][] numbers = { { 1, 2, 3, 4 },{ 5, 6,...
1. What will print? int[][] numbers = { { 1, 2, 3, 4 },{ 5, 6, 7, 8 },{ 9, 10, 11, 12 } }; System.out.println(numbers[1][3]); a) 13 b) 4 c) 8 d) 12 2. With what value does currYear = yearsArr[2] assign currYear? int[ ] yearsArr = new int[4]; yearsArr[0] = 1999; yearsArr[1] = 2012; yearsArr[2] = 2025;          a) 4 b) 1999 c) 2012 d) 2025 3. What will print? String [][] names = { { "Elliot", "Darlene", "Angela",...
Use a for loop to determine the sum of the rst 10 terms in the series 5k3, k % 1, 2, 3, . . . , 10.
Use a for loop to determine the sum of the rst 10 terms in the series 5k3, k % 1, 2, 3, . . . , 10.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT