program to print triangle
123454321
1234 4321
123 321
12 21
the numbers must be printed in this form.😕
Member • Jan 22, 2009
Member • Jan 22, 2009
Member • Jan 23, 2009
Member • Jan 27, 2009
silverscorpionI'll just give you the algorithm for now. try coding it yourself.. if you're not able to do it, let's see.
It goes like this:
Initialise 2 counters, let's say i and j.
Use one for printing the numbers in a single line, and the other for the number of lines.
Take care of the spaces in the lines. A simple thing to note is, if there are 'n' lines, then the k-th line has numbers from 1 to k-1, then 2*(k-1)-1 spaces, then numbers from k-1 to 1.
this same algo should work for any pattern, that is, even if the first line is 1234567654321, you can do it by this algo. Just try it.
Hope I'm clear..
Member • Jan 27, 2009
Member • Jul 25, 2011
disasterguys plz help me to write this progam
123454321
1234 4321
123 321
12 21
the numbers must be printed in this form.😕
Member • Jul 26, 2011
#include <stdio.h>
int main()
{
int i, j, n;
printf("Enter the number of Lines: ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
for(j=1; j<=n-i; j++)
printf("%d", j);
for(j=0; j<((i*2)-1); j++)
printf("*");
for(j=n-i; j>0; j--)
if(j!=n)
printf("%d", j);
printf("\n");
}
}
Member • Jul 27, 2011