Write a program that writes the following pattern, given the height (number of rows).
*
* *
* * *
* * *
* *
*
TURBO C programming?
Easy (the following code is standard C):
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int main()
{
int iNumRows;
int i, j;
div_t dt_result;
// get number of rows
printf("Number of Rows: ");
scanf("%d", %26amp;iNumRows);
dt_result = div(iNumRows, 2);
// print pattern
// half the rows
for (i = 1; i %26lt;= dt_result.quot; i++)
{
for (j = 1; j %26lt;= i; j++)
putchar('*');
putchar('\n'); // next row
} // end for half the rows
// center row for odd number of rows
if (dt_result.rem != 0)
{
for (j = 1; j %26lt;= i; j++)
putchar('*');
putchar('\n'); // next row
} // end if
// second half of rows
for (i = dt_result.quot; i %26gt; 0; i--)
{
for (j = 1; j %26lt;= i; j++)
putchar('*');
putchar('\n'); // next row
} // end for second half of rows
return 0;
}
cabbage
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment