![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 7
Rep Power: 0
![]() |
A for loop inside of another for loop
I am doing a project with consists in printing on the screen a arithmetic table in this format using two variable values:
1 + 0 = 1/// 1 * 0 = 0/// 1 - 0 = 0 1 + 1 = 2/// 1 * 1 = 1/// 1 - 1 = 1 1 + 2 = 3/// 1 * 2 = 2/// 1 - 2 = 0 1+ 3 = 4/// 1 * 3 = 3/// 1 - 3 = -2 1 + 4 = 5/// 1 * 4 = 4/// 1 - 4 = -3 ...... 1+ M=..../// 1 * M= ..../// 1 - M=.... N+ 0 = N/// N* 0 =0 /// N- 0=N N+ 1 = .../// N* 1 = N /// N- 1= N+ 2 = .../// N* 2 = .../// N- 2 N + M=....... M * N= M-N=...... I already did a part of it with this code: #include<stdio.h> main() { int num, mult, resp; for (num=1, mult=0; mult<5; mult++ ) { resp=num+mult; printf ("%d+%d=%d \n", num,mult,resp); } for (num=1, mult=0; mult<5; mult++) { resp=num*mult; printf ("%d*%d=%d \n", num,mult,resp); } for (num=1, mult=0; mult<5; mult++) { resp=num-mult; printf ("%d-%d=%d \n", num,mult,resp); } scanf ("%d", &num); return 0; } ...this prints the arithmetgic table with one perfectly, but I need to put those my three for loops inside of another for loop to increase the value of my num variable until it reaches the limit that I will choose (I am thinking about 5), instead of printing the table with only 1*0, 1*1..... I already tried this without sucess, I think that I am confused in relation to the functioning of the for loop. So how I can put this all inside of another for loop to increase the value of my num variable?. Thanks for the help Last edited by colt; Mar 20th, 2005 at 5:28 AM. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
for(i = 0; i < n; i++)
for(j = 0; j < 0; j++){
a = i+j; b = i*j; c = i-j;
printf("%d+%d=%d\t%d*%d=%d\t%d-%d=%d\n", i,i,a,i,j,b,i,j,c);
}
} . Good luck Dizz |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 7
Rep Power: 0
![]() |
That's basically the idea that I had, but it's written in a way that works.
Besides that, now the code is well more clean. Thanks ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|