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.
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.
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.
The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code...
The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code an O(nlog(n)) algorithm to count the number of inversions. Use the Merge sort Algorithm, and use the template below: (Use the file below that to test) countInv.cpp ------------------------------------------------------------------------------------------------------------------------------- #include <vector> #include <algorithm> using namespace std; int mergeInv(vector<int>& nums, vector<int>& left, vector<int>& right) { // Your code here } int countInv(vector<int>&nums) { // Your code here } CountInv_test.cpp ------------------------------------------------------------------------------------------------------------------------- #include <iostream> #include <vector> using namespace...
The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code...
The sequence 2, 4, 1, 3, 5 has three inversions (2,1), (4,1), (4,3). Using C++ Code an O(nlog(n)) algorithm to count the number of inversions. Use the Merge sort Algorithm, and use the template below: (Use the file below that to test) countInv.cpp ------------------------------------------------------------------------------------------------------------------------------- #include <vector> #include <algorithm> using namespace std; int mergeInv(vector<int>& nums, vector<int>& left, vector<int>& right) { // Your code here } int countInv(vector<int>&nums) { // Your code here } CountInv_test.cpp ------------------------------------------------------------------------------------------------------------------------- #include <iostream> #include <vector> using namespace...
Direction ratio of line joining (2, 3, 4) and (−1, −2, 1), are: A. (−3, −5, −3) B. (−3, 1, −3) C. (−1, −5, −3) D. (−3, −5, 5)
Direction ratio of line joining (2, 3, 4) and (−1, −2, 1), are:A. (−3, −5, −3)B. (−3, 1, −3)C. (−1, −5, −3)D. (−3, −5, 5)
How many different permutations are there of the numbers 1, 2, 3, 4, 5 so that...
How many different permutations are there of the numbers 1, 2, 3, 4, 5 so that the even numbers and the odd numbers alternate in the list?
Below are the number of hours spent exercising: 2 3 4 4 4 5 1 1...
Below are the number of hours spent exercising: 2 3 4 4 4 5 1 1 4 4 4 1 2 3 3 2 Which descriptive statistics from your output would you NOT report for Hours spent Exercising? Why not? Write a few sentences describing the data (use APA formatting). This interpretation should not include only the numbers, but rather what the numbers tell you about the data. Create a histogram for the hours spent exercising. You can do this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT