473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to choose one element from each array

nurulshidanoni
How to choose one element from each array., Which A(i)+B(i)+C(i)+D(i)+E(i)+F(i) must equal to 10.

__________________________________________________
i A B C D E F
__________________________________________________
1 3 2 3 3 2 4
__________________________________________________

2 6 9 4 24 5 7
__________________________________________________

3 11 28 5 81 10 12
__________________________________________________

4 18 65 6 192 17 19
__________________________________________________

5 27 126 7 375 26 28
__________________________________________________

6 38 217 8 648 37 39
_________________________
Nov 12 '07 #1
5 1732
amitpatel66
2,367 Expert 2GB
How to choose one element from each array., Which A(i)+B(i)+C(i)+D(i)+E(i)+F(i) must equal to 10.

__________________________________________________
i A B C D E F
__________________________________________________
1 3 2 3 3 2 4
__________________________________________________

2 6 9 4 24 5 7
__________________________________________________

3 11 28 5 81 10 12
__________________________________________________

4 18 65 6 192 17 19
__________________________________________________

5 27 126 7 375 26 28
__________________________________________________

6 38 217 8 648 37 39
_________________________
Please POST what you have tried to achieve this?
Nov 12 '07 #2
Expand|Select|Wrap|Line Numbers
  1. //total up the array
  2. //total + = total + a[i]
  3. total += a[i]
but, tehre is b,c,d,e,f ..i diont know ho w to do
Nov 12 '07 #3
amitpatel66
2,367 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. //total up the array
  2. //total + = total + a[i]
  3. total += a[i]
but, tehre is b,c,d,e,f ..i diont know ho w to do
You want a(i) + b(i) + c(i) + d(i) + e(i) = 10 right?

You try something like this:

Expand|Select|Wrap|Line Numbers
  1. int total = 0;
  2. for(int i = 0;i<10;i++)
  3. {
  4. total = a[i] + b[i] + c[i] + d[i] + e[i];
  5. if(total==10)
  6. {
  7. printf("total is 10");
  8. }
  9. total=0;
  10. }
  11.  
Nov 12 '07 #4
Why must total=0;?

and why == ?

Expand|Select|Wrap|Line Numbers
  1. printf("total is 10");
  2. }
  3. total=0;
  4. }
Nov 12 '07 #5
amitpatel66
2,367 Expert 2GB
Why must total=0;?

and why == ?

Expand|Select|Wrap|Line Numbers
  1. printf("total is 10");
  2. }
  3. total=0;
  4. }
== is a relational operator used in IF for comparison. You can learn about fundamentals of C here

And regarding total = 0, I have reinitialized the total variable so that next time it will store the sum for second value ie for i = 1 and so on.
Its always good to reinitialize/clear a variable value before using them again
Nov 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: D. Alvarado | last post by:
Hello, I have an array that contains numbers. Each element in the array is guaranteed to be unique. Let's say I have another variable which I know for certain is in the array, but I don't know...
10
by: Noah Spitzer-Williams | last post by:
Hello guys, I'm itinerating through my array using pointers in this fashion: image is unsigned char image do { cout << "image byte is: " << *image << endl;
6
by: lucy | last post by:
Hello comp.lang.js.I need a script to rotate a background image on each newpage load, given the id of the element and a list (array?)of 2 or more image paths ("img1.jpg", "img2.jpg", ...).Actually,...
9
by: Haobin | last post by:
Hi everyone, I have an ArrayList whose members are classes. These classes are derived from a same base class. The base class has a floating point array and a string. How do I access each element in...
2
by: Amrit Kohli | last post by:
Hello. I have the following code, to do a simple operation by copying the elements of a vector of strings into an array of char pointers. However, when I run this code, the first element in the...
4
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array...
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
7
by: Michael Bray | last post by:
Let's say I am using reflection to analyze my classes, and I have an array of another class. How do I get the base class that forms the array from a type? public class A { } A MyArray =...
2
by: Gestorm | last post by:
Suppose we have an array a, the idea is: build another array, int next, for each 0<i<N, next = next position of a in the sorted array, if a is the max, then next is undefined. For example, let the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.