Question

In: Computer Science

(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...

(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows:

0

0 1

0 1 2

0 1 2 3

0 1 2 3 … n-1

Solutions

Expert Solution

The output is:

code for copy:

#include<iostream>
using namespace std;
int main()
{
   //declare an integer variable n
   int n;
   cout<<"Enter the value of n: ";
   //read the value of n
   cin>>n;
   //nested for loop to print the following pattern
   cout<<"The pattern is :"<<endl;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<=i;j++)
       {
           cout<<j<<" ";
       }
       cout<<endl;
   }
}

I HOPE THIS WILL HELP YOU..........IF YOU HAVE ANY DOUBTS REGARDING IT PLEASE LET ME KNOW IN THE COMMENT SECTION.



Related Solutions

(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
ite a C program that prompts for and reads in a non-negative integer from the keyboard....
ite a C program that prompts for and reads in a non-negative integer from the keyboard. Read it into an int variable x. Then display the 32 bits in x from the lsb to the msb (so the display will show the value in x in binary with the bits in reverse order). For example, if you input 6, then your program displays 00000000000000000000000000000110 Use the algorithm given in class (repeatedly divide by 2). Use the / and % operators....
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
Using C++ Write a program that reads a text from the keyboard until the user presses...
Using C++ Write a program that reads a text from the keyboard until the user presses the “Enter” key. Your program must count the number of uppercase alphabets (A through Z), lowercase alphabets (a through z), digits (0 through 9) and any other characters. The other character count value should NOT include the “Enter” key. Display the count on the screen. You must use the in-built C++ character I/O functions in this program.
Question 1: Write a C program that reads a date from the keyboard and tests whether...
Question 1: Write a C program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid month...
Write a program that reads numbers from scanf1 (keyboard) and then sums them, stopping when 0...
Write a program that reads numbers from scanf1 (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions of this program, using the while, do-while, and for loops.
Write a C program that allows: Three integer values to be entered (read) from the keyboard,...
Write a C program that allows: Three integer values to be entered (read) from the keyboard, Display the sum of the three values on the computer screen as follows: The integers that you have entered are: a b c The sum of a , b & c is ______ Thank you! C Code: Output screen:
JAVA Write nested while loop that will print out this pattern, based upon a number entered...
JAVA Write nested while loop that will print out this pattern, based upon a number entered by the user. User enters 4: 1234 1234 1234 1234 User enters 2: 12 12
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT