Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 20th, 2006, 9:47 AM   #1
can342man
Newbie
 
can342man's Avatar
 
Join Date: Jan 2006
Location: London, Ontario, Canada
Posts: 16
Rep Power: 0 can342man is on a distinguished road
Array addition?

Hi everyone,

This maybe something very trivial, I am having trouble adding or multiplying elements of 2 or more arrays togethor. My original program is more complicted but this simple program may be a good example to test the ideas.

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main ()
{
	
	int i, j, k, t, num1[6], num2[6], numTot[6];	

// place 6 numbers in array num1
	for(t=0; t<=5; t++) {
		num1[t] = t;	
		cout << num1[t] << endl;
	}

// place 6 numbers in array num2
	for(j=5; j<=10; j++) {
		num2[j] = j;
		cout << num2[j] << endl;
	}

// sum of 2 arrays element by element
	for(k=0; k<=5; k++) {
		numTot[k] = num1[t] + num2[j];
		cout << numTot[k] << endl;
	}

}

Really appreciate it if anyone has some ideas.

Thanks.
__________________
Greatness courts failure and solitude.
--- Anonymous
can342man is offline   Reply With Quote
Old Apr 20th, 2006, 9:56 AM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Hope this makes sense to you:
#include <iostream>

using namespace std;

int main()
{
	int num1[6], num2[6], numTot[6];

	// place 6 numbers in array num1
	for(int t=0; t<=5; t++)
	{
		num1[t] = t;
		cout << "num1[" << t << "]: " << num1[t] << endl;
	}

	cout << endl;

	// place 6 numbers in array num2
	for(int j=0; j<=5; j++)
	{
		num2[j] = j;
		cout << "num2[" << j << "]: " <<  num2[j] << endl;
	}

	cout << endl;

	// sum of 2 arrays element by element
	for(int k=0; k<=5; k++)
	{
		numTot[k] = num1[k] + num2[k];
		cout << "numTot[" << k << "]: " <<  numTot[k] << endl;
	}
	return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 21st, 2006, 8:39 AM   #3
can342man
Newbie
 
can342man's Avatar
 
Join Date: Jan 2006
Location: London, Ontario, Canada
Posts: 16
Rep Power: 0 can342man is on a distinguished road
NNxion

That helped out a lot, I can't believe it was that simple.

Thanks for your help.
__________________
Greatness courts failure and solitude.
--- Anonymous
can342man 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 2:24 AM.

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