int main()
{
int n=9,half;
char a[9][9];
if(n%2 == 0)
half = n/2;
else
half = n/2 + 1;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i < half){
if(j<=i)
a[i][j]='*';
else
a[i][j]='-';
}else{
if(j<n - i)
a[i][j]='*';
else
a[i][j]='-';
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
printf("%c",a[i][j]);
}
printf("\n");
}
getch();
return 0;
}
On Jan 24, 9:32 am, "delboy" <[EMAIL PROTECTED]> wrote:
> OK, I need to write an algorithm to populate a 2D array A(i,j) of size
> n x n. There is 1 '*' in the 1st row, increasing to n/2 in the middle
> row, this decreases back to 1'*' in the last row. We can also assume
> that n is odd.
>
> *----------
> **---------
> ***-------
> ****------
> *****-----
> ****------
> ***-------
> **---------
> *----------
>
> Hope this clarifies things,
>
> Del.
>
> On Jan 24, 4:06 pm, "Sandesh" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Not clear,
> > give the full explanation .........
> > Sandesh Hegde
>
> > On Jan 24, 8:32 pm, "delboy" <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I'm trying to input the following values into a 2D array via some sort
> > > of method / algorithm. Any ideas on the best way to approach this?
>
> > > *----------
> > > **---------
> > > ***-------
> > > ****------
> > > *****-----
> > > ****------
> > > ***-------
> > > **---------
> > > *----------
>
> > > Thanks,
> > > Del- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---