Originally Posted by
Kecupochren
I would really appreciate any help, but rather then just giving me a finished code I would appreciate a "guidance". Thank you
Hello there,
What I understand from your problem (well, actually you may need to modify a bit my solution for the value range part inside a loop) is that:
Assuming that numberOfRows is the number of rows:
- For each row N you have to insert numberOfRows - N spaces before start printing sharps
- For each row N you have to print N times the sharp character
- And finally insert a new line character
You can try the following:
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int numberOfRows = 0;
int rowNumber = 0;
int counter = 0;
// start by asking the user the number of rows
printf("Enter the number of rows: ");
scanf("%d",&numberOfRows);
for (rowNumber = 0 ; rowNumber <= numberOfRows ; rowNumber++)
{
// For each row N you have to insert numberOfRows - N spaces
// before start printing sharps
for (counter = 0 ; counter < numberOfRows - rowNumber ; counter++)
printf(" ");
// For each row N you have to print N times the sharp character
for (counter = 0 ; counter < rowNumber ; counter++)
printf("#");
// And finally a new line character for the next loop iteration
printf("\n");
}
return 0;
}
Which gives the following result (I tested on Linux)
Code:
$ gcc -Wall testscript.c -o testscript
$ ./testscript
Enter the number of rows: 0
$ ./testscript
Enter the number of rows: 1
#
$ ./testscript
Enter the number of rows: 2
#
##
$ ./testscript
Enter the number of rows: 3
#
##
###
$ ./testscript
Enter the number of rows: 4
#
##
###
####
$ ./testscript
Enter the number of rows: 5
#
##
###
####
#####
$
Regards,
Dariyoosh