1. 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. Show some code.

3. 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. 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

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

Tim S.

5. ok i will try to code i will post them after awhile..

6. 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. 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..

9. 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.

10. 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. @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. 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.

13. really appreciate your help white flag, im gonna give it a try now..