Like Tree4Likes
  • 2 Post By stahta01
  • 1 Post By stahta01
  • 1 Post By whiteflags

Nested loops..

This is a discussion on Nested loops.. within the C Programming forums, part of the General Programming Boards category; Hi everybody, im a newbie in C programming and i got project which i need to submit them tomorrow and ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    8

    Unhappy Nested loops..

    Hi everybody,

    im a newbie in C programming and i got project which i need to submit them tomorrow and im really struggling with "while nested loops"..

    my problem is i don't know how to make it, so if somebody could help i will be really appreciated...

    my problem is i have values which are
    a1= 0.1 0.2 0.3 0.4 0.5
    a2= 0.5 0.6 0.7 0.8 0.9 1.0

    and i need to create two dimensional array by using while loop

    to be more clear i need the output to be like this

    total area=

    0.1/0.5 0.1/0.6 0.1/0.7 0.1/0.8 0.1/0.9 0.1/1.0
    0.2/0.5 0.2/0.6 0.2/0.7 0.2/0.8 0.2/0.9 0.2/1.0
    0.3/0.5 0.3/0.6 0.3/0.7 0.3/0.8 0.3/0.9 0.3/1.0
    0.4/0.5 0.4/0.6 0.4/0.7 0.4/0.8 0.4/0.9 0.4/1.0
    0.5/0.5 0.5/0.6 0.5/0.7 0.5/0.8 0.5/0.9 0.5/1.0


    so please if anyone who know how to do it please help me, i've trying to make it since a week but my problem is i just don't get the concept of nested while loops...

    thank you...

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Show some code.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    i would be showing you the code if i really know how to do it... but i really don't know how to start...

    please guys im really really really really in need for your helps...

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,485
    Announcements - General Programming Boards

    If you are not able to post any code; then no one is likely to help you with your problem.

    Since you can not write any code; I suggest starting at the beginning of the tutorial.
    http://www.cprogramming.com/tutorial/c-tutorial.html

    Link to loop section below

    For, While and Do While Loops in C - Cprogramming.com

    Tim S.
    Last edited by stahta01; 06-17-2012 at 12:25 PM. Reason: added more links
    her091 and antred like this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    ok i will try to code i will post them after awhile..

  6. #6
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    here is my code...

    Code:
    #include <stdio.h>
    #include <math.h>
    int main(void)
    {
    
    float a1max, a2max,  step,a1values, a2values;
    a1values=0.1, a2values=0.5;
    a1max=0.5, a2max=1.0;
    step=0.1 ;
    
    while (a1values <= 0.5)
    { 
    printf("a1values=%f\n\t",a1values);
    a1values=a1values+step;
    }
    
    printf("\n\n\n\n\n");
    while (a2values <= 1.1)
    {
    printf("a2values=%f\n\t",a2values);
    a2values=a2values+step;
    }
    
    /*here where is i want exactly nested while loops
    after obtaining all the values of a1values and a2values 
    now i need to calculate the area, which is 
    all the elements of a1values divide by the first value of a2valyes which are,
    0.1/0.5   0.2/0.5   0.3/0.5    0.4/0.5    0.5/0.5  
    all the values of a1values again divide by the second value of a2values which are,
    0.1/0.6   0.2/0.6   0.3/0.6    0.4/0.6    0.5/0.6
    
    and so on
    the nested loop look like this
    
    while(statement)
    { expression
    while(statement)    
    {expression
    
    and then print the total area of all the elements of a1values/one by one of elements a2values
    i have no clue how many loops i have to do as it really confuse me*/
    
    
    
    
    getch();
    }

  7. #7
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    can somebody help me please...

    i need to submit this project after 10 hours and i just struggling with the nested loops which i mentioned above, plus i need to write technical report too..

    please guys help me..

  8. #8
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    please help me man..

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    2,485
    This IS NOT nested while loop; or, at least it is NOT clearly a nested loop.

    Code:
    while(statement)
    { expression
    while(statement)   
    {expression
    Try something like below; normally statement2 would be used.
    Sometimes statement1 and/or statement3 will be used.
    The statement[1,2,3] are place holders for one or more C statements.

    Code:
    while(condition) {
       statement1;
       while(condition) {  
          statement2;
       }
       statement3;
    }
    Tim S.
    her091 likes this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    and then print the total area of all the elements of a1values/one by one of elements a2values
    i have no clue how many loops i have to do as it really confuse me*/
    It looks like you need one loop inside of an outer loop; that is 2 loops. You can do the printing with another two loops like this, separately or you can do it immediately after calculating, it's up to you.

    One problem I notice is that you aren't actually using a two dimensional array.

    Keep trying.

  11. #11
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    @white flags:

    could u please tell me how to create it then? the 2 dimesional array?
    i know im asking too much but im really in need for ur help...

    i need to submit them tomorrow..
    u might say i need to refer to tutorial but im really don't understand it, i've been visiting this website since a week.. but unforatunatel i don't understand..

    u guys are expert.. just show me how to create those pleaaaaaaase...

  12. #12
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Well you know how an array works right?
    Code:
     [ 0 | 1 | 2 | 3 | 4 ]
    That's an array with five elements. Each number is the index you need to put in brackets to access the value.
    The declaration is:
    Code:
     float foo[5];
    It should be easy to remember that the total size is 1 plus the highest index.

    When you want to make a two dimensional array, you can look at it like this:
    Code:
    [ (0,0) | (1,0) | (2,0) | (3,0) | (4,0) ]
    [ (0,1) | (1,1) | (2,1) | (3,1) | (4,1) ]
    So the first number in each ordered pair is the column, and the second is the row.
    You declare it like this:
    Code:
     float bar[4][4];
    So take that information and use it in your program.
    her091 likes this.

  13. #13
    Registered User
    Join Date
    Jun 2012
    Posts
    8
    really appreciate your help white flag, im gonna give it a try now..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested loops
    By zeondik in forum C# Programming
    Replies: 2
    Last Post: 10-26-2008, 06:58 AM
  2. Nested For Loops
    By smitsky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 12:58 PM
  3. nested for loops
    By akub3 in forum C Programming
    Replies: 2
    Last Post: 04-01-2004, 05:21 AM
  4. nested for loops/
    By o0o in forum C++ Programming
    Replies: 2
    Last Post: 12-28-2003, 09:19 AM
  5. Nested for loops
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2002, 09:25 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21