Results 1 to 3 of 3

Thread: Left handed right angled triangle with C Program using nested "for" loop

  1. #1
    Join Date
    Aug 2009
    Posts
    76

    Left handed right angled triangle with C Program using nested "for" loop

    I have recently started learning C programming. I have joined one classes for this. Now I decided to figure out how things works and so I am trying to make a left handed right angle with C Program. But the problem is that I am unable to figure out what the statements would be? I want to use nested "for" loop. Has anyone made a left handed right angled triangle with C Program using nested "for" loop as below?

    *
    **
    ***
    ****
    *****

  2. #2
    Join Date
    Nov 2008
    Posts
    1,054

    Re: Left handed right angled triangle with C Program using nested "for" loop

    Code:
    #include <stdio.h>
    void main()
    {
    int i, j, k, number;
    printf ("Enter the number :");
    scanf ("%d",&number);
    printf ("\n\n");
    for(i=1;i<=number;i++)
    {
    printf("\n");
    for(k=number-1;k>=i;k--)
    {
    printf(" ");
    }
    for (j=1;j<=i;j++)
    {
    printf("* ");
    }
    printf("\t\n");
    }
    for(i=number-1;i>=1;i--)
    {
    printf("\n");
    for(k=number-1;k>=i;k--)
    {
    printf(" ");
    }
    for(j=i;j>=1;j--)
    {
    printf("* ");
    }
    printf("\t\n");
    }
    }

  3. #3
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Left handed right angled triangle with C Program using nested "for" loop

    Here is more simpler code for Left handed right angled triangle in C language:

    Code:
    #include <stdio.h>
    void main()
    {
    	int i,j;
    	int n = 0;
    	printf ("Please enter the number: ");
    	scanf ("%d",&n);
    	for (i = 1; i <= n; ++i)
    	{
    		for (j = 1 ; j <= i; ++j)
    		{
    			printf ("*");
    		}
    		printf ("\n");
    	}
    }

Similar Threads

  1. never Left "Memory Clean" Enabled on BlackBerry Bold 9930
    By Kaalia in forum Portable Devices
    Replies: 7
    Last Post: 16-12-2011, 08:09 PM
  2. Replies: 10
    Last Post: 15-10-2010, 02:02 PM
  3. Replies: 5
    Last Post: 11-07-2010, 04:30 AM
  4. Replies: 15
    Last Post: 28-12-2009, 09:29 PM
  5. Can't open Hotmail msgs, "javascript;" @ lower left
    By Klangpup in forum Vista Help
    Replies: 3
    Last Post: 06-07-2008, 07:19 AM

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,727,301,708.37782 seconds with 17 queries