I have been trying to solve it.
But all I can get out is:
1
1 2
1 2 3
1 2 3 4
etc.
but I can't get out:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
my professor says that I need to add a "k" and increment it.
so I don't think that your response "Dhaydan" would work for him.
Can u see into the k that the professor is talking about.
Thanks.
that is all I got:
#include<iostream>
using namespace std;
int main()
{
int i, j, num;
cout<<"Enter a number: ";
cin>>num;
for(i=1; i<=num; i++)
{
for(j=1; j<=i; j++)
{
cout<< j ;
}
cout<<endl;
}
return 0;
}
But there is something missing that should get me the desired output.
When posting code, please use code tags. Highlight the code and click the "<>" button to the right of the edit window. It's also a good idea to indent your code to match the block structure.
Here is your code indented and tagged:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
usingnamespace std;
int
main()
{
int i, j, num;
cout << "Enter a number: ";
cin >> num;
for (i = 1; i <= num; i++) {
for (j = 1; j <= i; j++) {
cout << j;
}
cout << endl;
}
return 0;
}
I will repeat the relevant part of my original post:
The number that you print increments each time and has no relationship to the lines, so somewhere you're going to have something like:
1 2 3
int numToPrint = 1;
...
cout << numToPrint++;
The professor's "k" number is what I'm calling "numToPrint." Your bug is at line 11 where you print j. You need to print numToPrint (or k) at that point and increment it.
#include<iostream>
usingnamespace std;
int
main()
{
int i, j, k = 1;
for (i = 1; i <= 5; i++) {
for (j = 1; j <= i; j++) {
cout <<" "<< k++;
}
cout<<endl<<endl;
}
return 0;
}
could you try this on Visual Basic C++ for me? cuz mine has a problem, and I am doing an online compiler and I don't trust it.