Floyd's triangle

Discussion in 'C' started by Amit Kumar Saha, Aug 23, 2008.

  1. Amit Kumar Saha

    Amit Kumar Saha New Member

    Joined:
    Aug 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    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:
     
    Last edited: Aug 23, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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++;
    
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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++
    
     
  4. balaje26

    balaje26 New Member

    Joined:
    Sep 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.stuffebook.blogspot.com
    Floyds triangle full program...?
     
  5. Amit Kumar Saha

    Amit Kumar Saha New Member

    Joined:
    Aug 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    yes,
    Many thanks for showing interest.
     
  6. Amit Kumar Saha

    Amit Kumar Saha New Member

    Joined:
    Aug 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  7. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    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");
      }
    
     
  8. balaje26

    balaje26 New Member

    Joined:
    Sep 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.stuffebook.blogspot.com
    how to learn c easy
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Get someone else to do it. Programming is HARD.
     
  10. aadilprabhakar

    aadilprabhakar New Member

    Joined:
    Nov 18, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    India
    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
     
    Last edited by a moderator: Nov 18, 2008
  11. back from retirement

    back from retirement New Member

    Joined:
    Nov 9, 2008
    Messages:
    72
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Student, UG 1st Yr., Jadavpur University
    Location:
    Uttarpara, West Bengal, India
    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....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice