# how do i make a mathematical table using loops.

• 10-15-2005
how do i make a mathematical table using loops.
How do i write a program that has only two nested do......while loops that produces:
+ 5 10 15 20 25 30
50 55 60 65 70 75 80
40 45 50 55 60 65 70
30 35 40 45 50 55 60
20 25 30 35 40 45 50
10 15 20 25 30 35 40
• 10-15-2005
Salem
Well can you produce a single while loop which can generate the first row of the output?
Show us what you know so far, and don't forget the [code][/code] tags when posting code.
• 10-15-2005
Code:

```#include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); printf("+ "); i=5; do { printf("%4d"); i=i+1; }while(i<=30); }```
this is what i have so far i can output the first line but ican find away to output the rest.
• 10-15-2005
cwr
Remove conio.h/clrscr() from your code, they don't do anything useful and aren't portable.

main needs to return int, not void.

You do "printf("%4d");", but where is the variable you are printing?

Why do you have i=i+1 when you are supposed to go in steps of 5?

Suggest you re-post the code above so that it works, then we'll help with the "rest".
• 10-15-2005
Code:

```int main() { int  i,j;           printf("+");   i=5;  do {         printf("%4d",i);   i=i+5; }while(i<=30); }```
i=i+1 is for adding the value to the next value is added by 5.
• 10-15-2005
ingnore i=i+1, it is suposed to be i=i+5
• 10-15-2005
Salem
So now just wrap another loop (and another variable around that code
Code:

```int row = ?; do {     do {     } while ( i <= 30 ); } while ( row ? );```
Replace the ? with whatever you want to achieve the result you're after.
• 10-15-2005
could you please post the whole code am still having problems
• 10-15-2005
Alastor
isn't it easier to use 'for'?
• 10-15-2005
sand_man
Alastor: It's probably homework.
• 10-16-2005
I think the most effective way to do what you want is:

Code:

```#include <stdio.h> int main() {     printf(" +  5 10 15 20 25 30\n");     for(int i = 50; i >= 10; i-=10)     {         for(int j = 0; j <= 30; j+=5)         {             printf("%d ",i+j);         }         printf("\n");     }     return 0; }```
That, in my opinion, is the most effective way to achieve the effect that you want. Notice that the first line is a heading and not part of the actual loop.

If you must you two do...while loops then just set i and j ahead of time and increment them within the loop.
• 10-16-2005
quzah
No, the most "effiecient" way to do it it:
Code:

```do {     while(0);     puts(" +  5 10 15 20 25 30\n"         50 55 60 65 70 75 80\n"         40 45 50 55 60 65 70\n"         30 35 40 45 50 55 60\n"         20 25 30 35 40\n45 50\n"         10 15 20 25 30 35 40");     } while(0);```
Meeting their criteria of 2 loops.

PS: There's a reason we don't simply DO THE WHOLE GOD DAMN THING FOR THEM. It's so they actually TRY.

Quzah.
• 10-16-2005
prog-bman
quzah,
You are my role model.
• 10-18-2005