Last active
March 24, 2024 13:06
-
-
Save sezRR/d62a404ee5c828ca0837048be7a6353c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WRITE A PROGRAM TO DISPLAY THE FOLLOWING TRIANGLE, USING A FUNCTION | |
* | |
* OUTPUT: | |
* * | |
* *** | |
* ***** | |
* ******* | |
* ********** | |
* | |
*/ | |
#define _CRT_SECURE_NO_WARNINGS | |
#define ROW_COUNT 5 | |
#define OUTPUT_CHARACTER '*' | |
#include <stdio.h> | |
void drawChar(int times, char character) | |
{ | |
for (int i = 0; i < times; i++) | |
printf("%c", character); | |
if (character != ' ') | |
printf("\n"); | |
} | |
void drawTriangle(int rowCount, char character) | |
{ | |
for (int i = 1; i <= rowCount; i++) | |
{ | |
drawChar(rowCount - i, ' '); | |
drawChar(i * 2 - 1, character); | |
} | |
} | |
int main(void) | |
{ | |
drawTriangle(ROW_COUNT, OUTPUT_CHARACTER); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment