Jump to content
Admin2

Nested Loop Problem :| C Programming

Recommended Posts

Saya ada masalah ngan coding nested loop

Macam saya nak print yang ni

1

12

123

1234

12345

coding dia macam ni

#include <stdio.h>

int main()

{
int i, j;
for (i=1; i<=5; i++)

{


for (j=1;j<=i;j++)

{

printf("%d", j);
}

printf("\n");


}

}

camne nak print yang ni:

54321

4321

321

21

1

hurmm ada sape2 yang tau? betik.............?? hehe. sape2 ke..

Share this post


Link to post
Share on other sites

kodnya sama seperti diatas cuma reverse sahaja

for(i = 5; i >= 1; i--)
    {
        for(j = i; j >= 1; j--)
        {
            printf("%d", j);
        }
        printf("\n");
    }

Share this post


Link to post
Share on other sites

huhu thanx2. camne kalau yang ni pulak?

54321

5432

543

54

5

macam susah je..

Share this post


Link to post
Share on other sites

huhu thanx mykk. 5 bintang for u. nanti ada apa2 problem ngan nested loop sy post kat sini ok. thanx sekali lagi :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...