Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-03-2004, 07:47 AM   #1 (permalink)
Deenet
Registered User
 
Join Date: Nov 2004
Posts: 3
Deenet is on a distinguished road
hints for a problem

I need halp solving codng a simple program in C. The program has do be exclusively nested loops with the following inputs.
0
01
012
0123
01234
0123
012
01
0
I am looking for suggestions and ideas, not for someone to do my homework for me. I was able to do this using a for loop with nested if statements. But i need to do it with nested loops.

Thanks!
Deenet is offline   Reply With Quote
Old 11-03-2004, 08:04 AM   #2 (permalink)
Deenet
Registered User
 
Join Date: Nov 2004
Posts: 3
Deenet is on a distinguished road
Correction on the previous message

What I meant was I need to have the following OUTPUT:
0
01
012
0123
01234
0123
012
01
0

Thanks!
Deenet is offline   Reply With Quote
Old 11-03-2004, 01:29 PM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Some pseudo code:
Code:
valueA = 0
limit = 5
while (valueA < limit)
   valueB = 0
   while (valueB <= valueA)
      print valueB
      valueB = valueB +1
   valueA = valueA +1
   print <cr>
This takes care of the first part ie:
0
01
012
0123
01234

It's almost the same idear in the remaining part.
I'll be back tomorrow morning (atleast in my timezone) to post my solution






Edit:
I'm back, if you dont want to see the solution, then don't scroll past this line
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 11-03-2004 at 10:09 PM.
redhead is offline   Reply With Quote
Old 11-03-2004, 10:11 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
A solution to this could be:
Code:
#include <stdio.h>

int main()
{
  int count_outer, count_inner, limit;
  limit = 5;
  /* 
   * show the segment
   *
   * 0
   * 01
   * 012
   * 0123
   * 01234
   */
  for(count_outer = 0; count_outer < limit; count_outer++)
    {
      for (count_inner = 0; count_inner <= count_outer; count_inner++)
        {
          printf("%d", count_inner);
          fflush(stdout);
        }
      printf("\n");
      fflush(stdout);
    }
  --count_outer;
  /* 
   * show the segment
   *
   * 0123
   * 012
   * 01
   * 0
   */
  for( ; count_outer >= 0; --count_outer)
    {
      for(count_inner = 0; count_inner < count_outer; count_inner++)
        {
          printf("%d", count_inner);
          fflush(stdout);
        }
      printf("\n");
      fflush(stdout);
    }
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 11-04-2004, 03:54 AM   #5 (permalink)
Deenet
Registered User
 
Join Date: Nov 2004
Posts: 3
Deenet is on a distinguished road
Thanks guys, I will look into both of these!
Deenet is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript Problem dawkim HTML, XML, Javascript, AJAX 2 01-26-2004 07:02 PM
omfg... well, i may need help just understanding this problem... .pakmon. Standard C, C++ 3 01-08-2004 08:44 AM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
structure problem Goshi Standard C, C++ 5 04-21-2003 12:19 AM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM


All times are GMT -8. The time now is 11:56 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting