Hi All :mrgreen: ,
was mucking about with a small programme I have which makes a triangle pattern when entering in a number. It uses nested For loops.
I now want to create the same thing using functions as im only just beginning to learn the C language. I have started it but get One error. Maybe some nice person could suggest a few things ? :)
Heres the Nested For loop code
#include <stdio.h>
#include <conio.h>
void triangle(int n);
int main(void)
{
int rowLength;
int starCount;
int rowHeight;
printf("\n Enter a number to display a triangle: ");
scanf("%d", &rowHeight);
void triangle(int n);
for (rowLength = 1; rowLength <= rowHeight; ++rowLength)
{
printf("\n");
for (starCount = 1 ; starCount <= rowLength; ++starCount)
printf("*");
}
printf("\n");
getche();
}
and here is my attempt which isn't finished and need help with using Functions
#include <stdio.h>
#include <conio.h>
void triangle(int n);
int main(void)
{
int rowLength;
int rowHeight;
printf("\n Enter a number to display a triangle: ");
scanf("%d", &rowHeight);
for (rowLength = 1; rowLength <= rowHeight; ++rowLength)
{
printf("\n");
}
return rowHeight;
}
void triangle(int n, int starCount, int rowLength)
{
for (starCount = 1 ; starCount <= rowLength; ++starCount)
printf("*");
return starCount;
printf("\n");
getche();
}