#include
using namespace std;
int main()
{
int n;
cin>>n;
int row=1;
int val = 1;
while(row<=n)
{ int count = 1;
while(count<=row){
cout<<val<<" ";
val++;
count++;
}
cout<<endl;
row++;
}
}
above code gives correct pattern
but below code give incorrect just because of declaration of count outside 1st while. why?
#include
using namespace std;
int main()
{
int n;
cin>>n;
int row=1;
int count = 1;
int val = 1;
while(row<=n)
{
while(count<=row){
cout<<val<<" ";
val++;
count++;
}
cout<<endl;
}
}