Question

Number Pattern - Square number pattern - 10 Given two integers N1 and N2, display the...

Number Pattern - Square number pattern - 10

Given two integers N1 and N2, display the given number pattern(Square number patterns).

in zinger code with comment please

Input:
5

5

    where:

  • First line represents the value of N1( number of rows ).
  • Second line represents the value of N2( number of columns ).

Output:

1 1 1 1 1

   2 2 2 2 2

   3 3 3 3 3

   4 4 4 4 4

5 5 5 5 5

Homework Answers

Answer #1

Note that you have'nt mentioned any language.So I have coded it in C++.Although you can change it in any language if you understand the algorithm.

//Code starts here.

#include <iostream>

using namespace std;

int main()
{
int N1,N2; //Integers for N1 and N2
cin>>N1>>N2; //Taking input for N1 and N2
int i,j; //Variables for loops
for(i=1;i<=N1;i++) //Outer loop,will run for N1(no. of rows) times
{
if(i!=1&&i!=N1) //Print extra space every row except first and last
cout<<" ";
for(j=1;j<=N2;j++) //Inner loop,will run for N2(no. of columns) times
{
cout<<i<<" "; //Print value of i
  
}
cout<<endl; //Change line after every row
}
return 0;
}
//Code ends here

Output

Python code

#Code starts here


#First take N1 and N2 as input after converting into int
N1 =int(input())
N2 =int(input())

for i in range(1,N1+1): #will run from 1 to N1(no of rows)
if i!=1 and i!=N1: #For empty spaces except first and last row
print(end=' ')
for j in range(1,N2+1): #will run for N2 times(no. of columns)
print (i,end=' ')
print() #Line change
#End of program

Output for two runs

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Linux 2)   Write a bash script which when executed, expects two integers, say n1 and n2....
Linux 2)   Write a bash script which when executed, expects two integers, say n1 and n2. If the first argument, n1, is greater than the second argument, n2, the script calls a function (written within the script) and passes to the function n1 and n2 to compute the sum from n1 to n2. This function returns the sum which the script prints. If n1 is not greater than n2, the script calls the same function and passes the n1 and...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is -3 10...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection. 2.      Program should display the patterns below. Additionally, you need to create your own pattern. 3.      Do not modify myPatterns6 driver. 4.      Make sure you document the program and its functions. 5.      PatternI is already implemented. 6.      Create five additional functions (similar to PatternI function) to implement Patterns II,...
We are given an array A of size n containing n positive and negative integers (the...
We are given an array A of size n containing n positive and negative integers (the array is indexed starting from 0). Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n and Pk=j k=i A[k] is maximized. Input sequence: [2, -4, 1, 9, -6, 7, -3] Output: [1, 9, -6, 7] or i = 2 and j = 5 Input sequence: [1, 2, 3, 4, 5, 6, -3] Output: [1,...
Two people enter the elevator in a 5-floor building. Let N1 and N2 denote the floors...
Two people enter the elevator in a 5-floor building. Let N1 and N2 denote the floors that they want to go to. Assume that N1 and N2 are independent and equtl to 2, 3, 4 and 5 with probabilities 1/4 each. (a) Write down the joint PMF (b) Calculate P(N1 > N2) and P(N1 = N2) (c) Let X1 and X2 denotethenumberofstopsthateachofthemwillmakebeforearriving to their floor. What is the support of X1 and X2? (d) Find the marginal PMF-s and the...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to...
Given two independent random samples with the following results: n1 = 226 ^p1 = 0.55 n2...
Given two independent random samples with the following results: n1 = 226 ^p1 = 0.55 n2 = 444 ^p2 = 0.63 Can it be concluded that the proportion found in Population 2 exceeds the proportion found in Population 1?  Use a significance level of α=0.1 for the test. Step 1 of 5: State the null and alternative hypotheses for the test. Step 2 of 5: Compute the weighted estimate of p, p‾. Round your answer to three decimal places. Step 3...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT