hi. im trying to create a program in which the user inputs the character and the level. this would output to a triangle and an inverted triangle. i have already figured out the triangle but i cant seem to get the right output for the inverted triangle

#include <stdio.h>
#include <conio.h>

void main()

{
	int n;
	int m;
	int o;
	char p;

	clrscr();

	printf("Enter a symbol: ");
	scanf("%c", &p);
	printf("Enter levels for traingles: ");
	scanf("%d", &n);
	printf("\nNormal triangle:\n");



	for (m=1; m<=n; m++)
	{
		printf("\n");

		for (o=1; o<=m; o++)
		{
			printf("%c", p);
		}
	}

	printf("\n\nInverted triangle:\n");

	for (m=n; m>0; m--)
	{

		printf("\n");

		for (o=n; o>0; o--)
		{
			printf("%c", p);
		}
	}
	getch();
}

an example output of the 2nd loop is:

entered character: #
entered level: 6

ouput:
######
######
######
######
######
######

pls help. tnx.

>for (o=n; o>0; o--)
Each row of the second triangle is based on n, and n doesn't change throughout your program. I believe you want to set o to m instead.

1. main returns int, not void

2. Avoid single letter identifiers (with the exception of i,j as being ubiquitous loop variables). For example, o and 0 make for very unreadable code.

yes. thanks for the tip. but i just used that because so that i could finish typing fast.

This question has already been answered. Start a new discussion instead.