I received this problem from my teacher, could someone help me with it?
Number Triangle - Print the following pattern, using horizontal tabs to separate
numbers in the same line. Let the user decide how many lines to print (i.e. what
number to start at):
4
3 3
2 2 2
1 1 1 1
I have this so far:
<#include<iostream>
using namespace std;
int main () {
int x;
int y=0;
cout << "Enter a number." << endl;
cin >>x;
cout << x << endl;
while (x!=0){
cout << x-1 << endl;
cout << y+1 << "\t" << endl;
x--;
}
}>
I know it isn't right, but it's my best attempt thus far. We've also studied for loops and voids.
#include <iostream>
int main()
{
std::cout << "enter a number: " ;
int number ;
std::cin >> number ;
int i = 0;
int cnt = 1 ;
while( number > 0 )
{
i = 0;
while (i < cnt)
{
std::cout << number << ' ' ;
i++;
}
std::cout << '\n' ;
--number ;
++cnt ;
}
}
enter a number: 4
4
3 3
2 2 2
1 1 1 1
Program ended with exit code: 0