From C to C++

Hi guys here I have two codes from C and C++
Code of C:
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
28
29
30
31
32
33
34
#include <stdio.h>

long n;

int main()
{
	long i,j,num,art;
	scanf("%ld",&n);

	num = n;

	for(i=0;i<n;i++)
	{
		for(j=0;j<(n-num)/2;j++)
		printf(" ");
		
		for(j=0;j<num;j++)
		printf("%ld",i+1);
		printf("\n");

		if(i < n/2)
		num -= 2;

		else
		num += 2;

		if(n%2 == 0 && i == (n/2-1))
		num += 2;
	}

	getchar();
	getchar();
	return 0;
}

Here the code of C++:
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()
{

   long int i,j,num;
    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;
}

*** The First C code shows number in Sand Watch Shape.
*** The Second C++ code shows numbers in Sand Shape but adds extra line of numbers. For example I input number : 3 It shows:
1
2
3
4
111
 2
333
444444
- The last line I don't need it. C code shows without this last line of numbers. Can You help me on that, cuz I can't Find the way to solve it. Thanx in Advance!
I told you in your other thread, it's because of this:
for(i=0;i<=n;i++)
Replace the <= by a < and you're all good.
I am very thankful for that Thank you hanst99 you helped me a lot :)
Topic archived. No new replies allowed.