# Thread: What is the Code for Floyd's triangle in C ??

1. Member
Join Date
Jul 2006
Posts
218

## What is the Code for Floyd's triangle in C ??

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..

2. Member
Join Date
Apr 2008
Posts
1,949

## Re: What is the Code for Floyd's triangle in C ??

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.

3. Member
Join Date
May 2008
Posts
2,015

## Re: What is the Code for Floyd's triangle in C ??

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.

4. Member
Join Date
May 2008
Posts
2,302

## Re: What is the Code for Floyd's triangle in C ??

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.

5. Member
Join Date
Nov 2005
Posts
1,322

## Re: What is the Code for Floyd's triangle in JAVA ??

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");
}
}
}

6. Member
Join Date
May 2008
Posts
2,393

## Re: What is the Code for Floyd's triangle in C ??

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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•