Please Help me in Floyd's triangle Friends, How can I control the increment of variable in floyd triangle. And I how should I initialize? another optional problem what is cycle length between and including two int number. Thanking you in advance... Amit :nice:
I'm not really sure what you mean. I'd use three variables for that, one containing the current number, one containing the number of numbers in the current line, and the third would be a loop from 0 to the second. Probably something like: Code: int i=1, j=1; for (k=0; k<j; k++) printf("%d ",i++); printf("\n"); j++;
I'm not really sure what you mean. I'd use three variables for that, one containing the current number, one containing the number of numbers in the current line, and the third would be a loop from 0 to the second (plus some sort of bailout condition). Probably something along the following lines: Code: int i=1, j=1 for k=0..j printf(i++) printf("\n") j++
brothers, plz don't mind I have forgot how to start a new thread. Plz pardon me for this. help me in this problem first.
xpi0t0s has already answered your question. To recap, something like this: Code: int column, line, n = 1; for (line = 0; line < number_of_lines; ++line) { for (column = 0; column <= line; ++column) printf ("%3d ", n++); printf ("\n"); }
Code: import java.util.*; import java.math.*; import java.io.*; public class pyramid{ public static void main(String argsp[]){ int i=1,j; int num = 1; while(num<=91){ for(j=1; j<=i; j++){ System.out.print (num + " "); num++; } i++; System.out.print("\n"); } } } Heres a solution to Floyds Triangle in JAVA
Have a look at my argument...it's similar, except for the display is in a equilateral triangular fashion.... Code: #include<stdio.h> #include<conio.h> #define m 4 void main() { int i,j,c,n=1,p=m; for(i=0;i<m;i++) { for(c=p;c>=0;c--) { printf(" "); } for(j=0;j<=i;j++) { printf("%d ", n); n++; } printf("\n"); p--; } getch(); } Cheers....