Sand Watch from Numbers
Here I figure out the code it works the only thing it shows one additional line of numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include<iostream>
using namespace std;
int n;
int main()
{
int i,j,num,art;
cout<<"Enter a number: ";
cin>>n;
num=n;
for(i=0;i<=n;i++)
{
for(j=0;j<(n-num)/2;j++)
cout<<" ";
for(j=0;j<num;j++)
cout<<i+1;
cout<<'\n';
if(i<n/2)
num-=2;
else
num+=2;
if(n%2==0 && i==(n/2-1))
num+=2;
}
system("pause");
return 0;
}
|
Nice. A bit weird, but it works. It should be <n instead of <=n.
Topic archived. No new replies allowed.