Is it possible to be done with array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is it possible to be done with array?

You traverse through the array elements. Print the every sum of two elements of array. Example: int array[] = {1, 2, 3}; Output:3, 4, 5

17th Sep 2021, 5:14 AM
TeaserCode
4 Answers
+ 2
Yes it's possible Do you want it like this na 1 + 2 = 3 1 + 3 = 4 2 + 3 = 5 ... ...
17th Sep 2021, 5:30 AM
Mohd Aadil
Mohd Aadil - avatar
+ 2
Yes it's possible using nested loop https://code.sololearn.com/c6VZ72rs3W19/?ref=app
17th Sep 2021, 6:58 AM
Ipang
0
int sum = 0; for (int i = 0; i < sizeof (array) / sizeof(array[0]); i++) { for (int j = i + 1; j < sizeof (array) / sizeof(array[0]); j++) { sum += array[i] + array[j]; } }
17th Sep 2021, 7:20 AM
Mani_K_A
0
I highly recommend you to solve it for 3,4,5... Elements
17th Sep 2021, 7:21 AM
Mani_K_A