Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 20th, 2005, 5:26 AM   #1
colt
Newbie
 
Join Date: Mar 2005
Posts: 7
Rep Power: 0 colt is on a distinguished road
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.
colt is offline   Reply With Quote
Old Mar 20th, 2005, 9:07 AM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
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);
  }
}
i think this should work and if not it should get you int he right direction.. Good luck
Dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Mar 21st, 2005, 1:29 AM   #3
colt
Newbie
 
Join Date: Mar 2005
Posts: 7
Rep Power: 0 colt is on a distinguished road
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
colt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC