
December 14th, 2003, 11:08 PM
|
|
Junior Member
|
|
Join Date: Dec 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
leading spaces in a printf
I am new to C programming. I have written a program that prints a pattern using astericks. It begins with a single '*' and increases each line, up to 10. However, I cannot figure out how to print with leading spaces. For example, I need to print the first row as 10 astericks, no spaces. Then, the next row should begin with 1 space and then print 9 astericks. Then, 2 spaces and then print 8 astericks, etc.
#include <stdio.h>
/* function main begins program execution */
int main ()
{
for( int cnt = 10; cnt >= 1; cnt--)
{
for( int k = 1; k <= cnt; k++)
printf( "*" );
printf( "\n" );
}
printf( "\n" );
for( int cntr = 1; cntr <= 10; cntr++)
{
for( int l = 1; l <= cntr; l++)
printf( "*" );
printf( "\n" );
}
return 0; /*indicate program ended successfully*/
} /*end function main*/
Please help!
|