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
|
Go4Expert Member
|
|
| 23Aug2008,08:27 | #1 |
|
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
Last edited by Amit Kumar Saha; 23Aug2008 at 08:35.. |
|
Mentor
|
![]() |
| 26Aug2008,03:45 | #2 |
|
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++;
|
|
Mentor
|
![]() |
| 26Aug2008,12:25 | #3 |
|
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++
|
|
Newbie Member
|
|
| 16Sep2008,21:43 | #4 |
|
Floyds triangle full program...?
|
|
Go4Expert Member
|
|
| 17Sep2008,01:11 | #5 |
|
yes,
Many thanks for showing interest. |
|
Go4Expert Member
|
|
| 17Sep2008,01:22 | #6 |
|
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. |
|
Ambitious contributor
|
|
| 17Sep2008,06:12 | #7 |
|
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");
}
|
|
Newbie Member
|
|
| 17Sep2008,20:34 | #8 |
|
how to learn c easy
|
|
Mentor
|
![]() |
| 17Sep2008,22:08 | #9 |
|
Get someone else to do it. Programming is HARD.
|
|
Newbie Member
|
|
| 18Nov2008,11:54 | #10 |
|
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");
}
}
}
Last edited by shabbir; 18Nov2008 at 16:26.. Reason: Code block |