Hi Friends. I am very new to the C Language. How do i build a Floyd's Triangle in C? Also how can I control the increment of variable in Floyd Triangle. And I how should I initialize? Please provide me the code or explain the logic..
Hi Friends. I am very new to the C Language. How do i build a Floyd's Triangle in C? Also how can I control the increment of variable in Floyd Triangle. And I how should I initialize? Please provide me the code or explain the logic..
~*~Silent~Kid~*~
"To The World You May Be Just One Person, But To One Person You May Be The World"
I think that you should try the following code for Floyd's triangle :
main void()
{
int num;line_num=1;
printf("enter a number");
scanf("\n");
while (line_num<=n)
{
count=1
while (count<=line_num)
{
printf("%d \t",num++);
count++;
}
printf("\n");
line_num++;
}
}
Hope that you will get the desired answer.
I don't know what exactly you mean when you said "How I control the increment of variable in Floyd Triangle?". I think that you should try this :
Here I have used the three variables, one foe 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. Here is the code :
int i=1, j=1;
for (k=0; k<j; k++)
printf("%d ",i++);
printf("\n");
j++;
Hope that you were looking for same.
I think that the code told by the katty should work. Since I don't know much about the C Language, I am just guessing. But can anyone tell me the code for the Floyd's triangle in Java.?? I think that some should be knowing this..!! Please help me since I want that for my tutorial.
Here is the Code for Floyd's triangle in Java. You can try this code :
import java.io.*;
import java.util.*;
import java.math.*;
public class pyramid{
public static void main(String arg[]){
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");
}
}
}
I am sure that the code given by the absolute55 should work for the java. Since I have not checked that personally, but seeing the logic I think that it should work. If you are having any error you can post it here. I will try to solve the issue as earlier as possible.
Bookmarks