-1

Hi
I've been asked to write a program for this figure

1234
2   3
3   2
4321

I have tried writing this,don't know if its correct or not :?:

my program is

#include <iostream.h>
void main()
{int n,r,c;
cout<<"enter the value of n"<<endl;
cin>>n;
for(r=1;r<=n;r++)
c=r;
cout<<c;
cout<<endl;
for(r=2;r<n;r++)
for(c=2;c<=r;c++)
cout<<c;
for(c=2;c<=n-1;c++)
cout<<" ";
c=r;
cout<<c;
cout<<endl;
for(r=3;r<n;r++)
for(c=3;c<=r;c++)
cout<<c;
for(c=3;c<=r+1;c++)
cout<<" ";
c=r-1;
cout<<c;
cout<<endl;
for(r=4;r<=n;r--)
c=r;
cout<<c;
cout<<endl;
}

Edited by happygeek: fixed formatting

Votes + Comments
Use code tags.
4
Contributors
3
Replies
4
Views
13 Years
Discussion Span
Last Post by alc6379
0

What does YOUR program output?

Also, you can use the code symbols to make the code more readable; they are:

[ <the word 'CODE'> ]
insert your code here
[ <a slash '/'> <the word 'CODE'> ]

Otherwise its pretty hard to follow all those nested for loops!

0

What does YOUR program output?

Also, you can use the code symbols to make the code more readable; they are:

[ <the word 'CODE'> ]
insert your code here
[ <a slash '/'> <the word 'CODE'> ]

Otherwise its pretty hard to follow all those nested for loops!

yeah, code tags look like this:

[code] your code goes here
[/code]

Note: looking at the editing of the posts, there's not any actual indentation in there that I can see...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.