Results 1 to 6 of 6

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

  1. #1
    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..
    ~*~Silent~Kid~*~
    "To The World You May Be Just One Person, But To One Person You May Be The World"

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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. #3
    Join Date
    May 2008
    Posts
    2,012

    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. #4
    Join Date
    May 2008
    Posts
    2,297

    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. #5
    Join Date
    Nov 2005
    Posts
    1,323

    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. #6
    Join Date
    May 2008
    Posts
    2,389

    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.

Similar Threads

  1. How to create rounded triangle in Illustrator?
    By Cheenu in forum Windows Software
    Replies: 5
    Last Post: 21-07-2011, 07:08 PM
  2. Triangle generator
    By gelsys1208 in forum Software Development
    Replies: 3
    Last Post: 13-10-2010, 04:32 AM
  3. Triangle using C++
    By Brake Fail in forum Software Development
    Replies: 4
    Last Post: 04-02-2009, 11:54 PM
  4. Want To Print Triangle In C++
    By vishodhan in forum Software Development
    Replies: 1
    Last Post: 08-01-2009, 09:53 PM
  5. Yellow triangle in the taskbar
    By harakim in forum Windows Software
    Replies: 3
    Last Post: 03-10-2008, 03:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,300,203.54125 seconds with 17 queries