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.
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.
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.
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)
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT