Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5248
Number of posts: 16673

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
for loop--check my sample program Posted by trebla2352 on 22 Sept 2008 at 5:13 AM
this is the for loop output. i'm still figuring out if i'm going to use function call in this type of problem.. do you have any idea with regards to this problem? MY sample program here was to long, i think there is an easy way to cope it shorter..

i started it with this,

#inlcude<stdio.h>
int main()
{
int i,j;
for(i=1;i<=3;i++)
  { for( j=0; j<i; j++)
       {printf("*");
         printf("\n");
        }
for(i=2; i<=4; i++)
  {for(j=0;j<i;j++)
        {printf("*");
         printf("\n);
        }
for(i=3; i<=5; i++)
  {for(j=0;j<i;j++)
        {printf("*");
         printf("\n);
        }
for(i=4; i<=5; i++)
  {for(j=0;j<i;j++)
        {printf("*");
         printf("\n);
        }
for(i=5; i<=6; i++)
  {for(j=0;j<i;j++)
        {printf("*");
         printf("\n);
        }
return 0;
}


THIS IS THE OUTPUT:
*
**
***
**
***
****
***
****
*****
****
*****
******
Report
Re: for loop--check my sample program Posted by Lundin on 22 Sept 2008 at 6:37 AM
Here is some "pseudo code" to give some hints (ie code that is nonsense syntax-wise but correct algorithm-wise):

stars=1;

for(i=0; i<rows; i++)
{
  for(j=0; j<line_width; j++)
  {
    print [line_width - stars] spaces
    print [stars] stars
    stars++;
  }

  for(j=line_width; j>0; j--)
  {
    /* do the reverse */
  }
}

Report
Re: for loop--check my sample program Posted by trebla2352 on 22 Sept 2008 at 7:08 AM
ok...
is there any form that is more simple and common to my program?
i'm not familiar with psuedo code.. tanx



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.