given an integer, write a program in C++ that displays
the number as follows
first line all
digits
second line all except first digit
...
last line
last digit
ex)
5 6 7 8
6 7 8
7 8
8
Greetings!!
Code:
#include <iostream>
using namespace std;
int main()
{
int n,k; //varible declaration
cout << "Please enter a number" << endl;
cin >> n; //read n
k=n; //save n to k
for(int j=0;j<k;j++) //control newline n times
{
for(int i=n+1;i<=2*k;i++) //control the values from n+1 to
2n
{
cout << i; //print the values
}
n=n+1; //after every line increment the number
cout << endl; //print newline
}
return 0;
}
Output screenshot:
Hope this helps
Get Answers For Free
Most questions answered within 1 hours.