Hi there; i'm a newbie when it comes to everything coding, and I have an assignment due tomorrow. The assignment is to code a triangle that begins with an '&' in the leftmost position of EVERY line, and in the case of line 1 the remaining 49 spots of the string will remain black. In the case of the remaining lines (2-32), I must print a '&' if the position above it on the previous line and the position above it and to the left of the previous line are different, otherwise it is again black. Oh, and I'm using Microsoft Visual to compile my code.
My thought process beginning was to create a string: line[50]="&" and move from there. However, everything I try to get this to work comes out all screwy and resembles nothing close to what is required. Here's an example of what i've tried:
Any help or advice will be greatly appreciated. Thanks.
My thought process beginning was to create a string: line[50]="&" and move from there. However, everything I try to get this to work comes out all screwy and resembles nothing close to what is required. Here's an example of what i've tried:
Code:
/* TRIANGLE PATTERN*/
#include <stdio.h>
#include <string.h>
#define SIZEOF 49
int main(void)
{
/* DECLARATIONS */
char space = ' ';
char line[50] = "&";
char add[2] = "&";
char adds[2] = " ";
int counter;
int loopCount = 0;
/* DISPLAY FIRST LINE */
printf("%s", line);
/* DESIGN & PRINT REST OF THE LINES */
while(loopCount < 35)
{
for(counter = 1; counter < SIZEOF; counter ++)
{
if(line[counter] != line[counter - 1])
{
strcat(line, add);
}
}
loopCount = loopCount + 1;
printf("\n%s", line);
}
return 0;
}
Comment