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;
}
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...
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:
#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;
}