drawing rectangle

can anyone shows me the source codes using<stdio.h> for drawing this rectangle?
55555
55555
45555
34555
23455
12345
thanks.get stucked in half way...
It looks like a 2d array, are that numbers neccessary and has a pattern or some algorithm to follow ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

int main ()
{
    int arr[6][5] = { /* I don't like to write all those numbers ? */ };

    int i, j;

    for ( i = 0; i < 6; i++ ) {
        for ( j = 0; j < 5; j++ ) {
            printf ( "%i ", arr[i][j] );
        }
        printf ( "\n" );
    }

    return 0;
}
Last edited on
thanks for your answers.but it's only required function & loops only...nt using array...do you have any other ways?....yes....it's compulsory to have the exactly number pattern as shown...
When you say you get stuck half way, what code did you use, could you post it here?
I only managed to get the 1st two lines which is:
55555
55555
I'm nt sure wether how to continue my codes...that's what I mean...thanks.
Yes, ok, that's the output. But what program code did you use?
#include<stdio.h>
int main(void)
{
int b;
printf("Enter The Height Of Rectangle:");
scanf("%d",&b);

for(int a=1;a<=2;a++)
{
for(int i=1;i<=b;i++)
printf("%d",b);
printf("\n");
}
get stucked until here...thanks.
Ok, thank you. That's interesting. I didn't realise that the height was variable (supplied by the user).
I think you're on the right lines using nested loops. You might find this useful as a hint of one possible solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

int f(int row, int col)
{
    // change this function
    // so that it returns a suitable value
    // based upon row and col
    
    return 1;
}

int main ()
{
    for (int row = 6; row > 0; row-- )
    {
        for (int col = 0; col < 5; col++ )
        {
            printf ( "%i", f(row,col) );
        }
        printf ( "\n" );
    }

    return 0;
}

Topic archived. No new replies allowed.