Program to find a pair with the given number in arrayCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow do I empty an array in JavaScript?Improve INSERT-per-second performance of SQLite?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Simulating a probability of 1 of 2^N with less than N random bits
Proof of Lemma: Every integer can be written as a product of primes
Can a Bard use an arcane focus?
Java - What do constructor type arguments mean when placed *before* the type?
Does "Dominei" mean something?
Meta programming: Declare a new struct on the fly
How can I successfully establish a nationwide combat training program for a large country?
Teaching indefinite integrals that require special-casing
For airliners, what prevents wing strikes on landing in bad weather?
Can I create an upright 7-foot × 5-foot wall with the Minor Illusion spell?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
Would it be legal for a US State to ban exports of a natural resource?
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Lifted its hind leg on or lifted its hind leg towards?
Resetting two CD4017 counters simultaneously, only one resets
Can a malicious addon access internet history and such in chrome/firefox?
Why is delta-v is the most useful quantity for planning space travel?
Partial sums of primes
Can the electrostatic force be infinite in magnitude?
What to do when my ideas aren't chosen, when I strongly disagree with the chosen solution?
Can the harmonic series explain the origin of the major scale?
A workplace installs custom certificates on personal devices, can this be used to decrypt HTTPS traffic?
My boss asked me to take a one-day class, then signs it up as a day off
Are Warlocks Arcane or Divine?
Program to find a pair with the given number in array
Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow do I empty an array in JavaScript?Improve INSERT-per-second performance of SQLite?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
#include <stdio.h>
int main()
int num[] = 6, 8, 4, -5, 7, 9 ;
int sum = 0;
for (int i = 0; i < 6; i++)
for (int j = i + 1; j < 6; j++)
sum = num[i] + num[j];
if (sum == 15)
printf("%dn%d", num[i], num[j]);
return 0;
I'm trying to find a pair of numbers in the array with a sum of 15. The expected output is 6 & 9. But I'm getting output as 6, 98, 7. What is wrong?
EDIT: The issue was not giving a new line after the first result. Sorry.
c arrays sum
add a comment |
#include <stdio.h>
int main()
int num[] = 6, 8, 4, -5, 7, 9 ;
int sum = 0;
for (int i = 0; i < 6; i++)
for (int j = i + 1; j < 6; j++)
sum = num[i] + num[j];
if (sum == 15)
printf("%dn%d", num[i], num[j]);
return 0;
I'm trying to find a pair of numbers in the array with a sum of 15. The expected output is 6 & 9. But I'm getting output as 6, 98, 7. What is wrong?
EDIT: The issue was not giving a new line after the first result. Sorry.
c arrays sum
1
8 + 7 = 15
I don't see the issue here.
– Joel Trauger
Mar 21 at 14:48
add a comment |
#include <stdio.h>
int main()
int num[] = 6, 8, 4, -5, 7, 9 ;
int sum = 0;
for (int i = 0; i < 6; i++)
for (int j = i + 1; j < 6; j++)
sum = num[i] + num[j];
if (sum == 15)
printf("%dn%d", num[i], num[j]);
return 0;
I'm trying to find a pair of numbers in the array with a sum of 15. The expected output is 6 & 9. But I'm getting output as 6, 98, 7. What is wrong?
EDIT: The issue was not giving a new line after the first result. Sorry.
c arrays sum
#include <stdio.h>
int main()
int num[] = 6, 8, 4, -5, 7, 9 ;
int sum = 0;
for (int i = 0; i < 6; i++)
for (int j = i + 1; j < 6; j++)
sum = num[i] + num[j];
if (sum == 15)
printf("%dn%d", num[i], num[j]);
return 0;
I'm trying to find a pair of numbers in the array with a sum of 15. The expected output is 6 & 9. But I'm getting output as 6, 98, 7. What is wrong?
EDIT: The issue was not giving a new line after the first result. Sorry.
c arrays sum
c arrays sum
edited 2 days ago
chqrlie
61.9k848105
61.9k848105
asked Mar 21 at 14:45
CombospiritCombospirit
83117
83117
1
8 + 7 = 15
I don't see the issue here.
– Joel Trauger
Mar 21 at 14:48
add a comment |
1
8 + 7 = 15
I don't see the issue here.
– Joel Trauger
Mar 21 at 14:48
1
1
8 + 7 = 15
I don't see the issue here.– Joel Trauger
Mar 21 at 14:48
8 + 7 = 15
I don't see the issue here.– Joel Trauger
Mar 21 at 14:48
add a comment |
2 Answers
2
active
oldest
votes
The issue was not giving a new line after the first result.
replace
printf("%dn%d",num[i],num[j]);
by
printf("%d,%dn",num[i],num[j]);
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
add a comment |
i find nothing wrong here 9+6=15
and 8+7=15
and also in printf instead of
printf("%dn%d",num[i],num[j]);
use
printf("%d %dn",num[i],num[j]);
you will get well suited output
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283103%2fprogram-to-find-a-pair-with-the-given-number-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The issue was not giving a new line after the first result.
replace
printf("%dn%d",num[i],num[j]);
by
printf("%d,%dn",num[i],num[j]);
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
add a comment |
The issue was not giving a new line after the first result.
replace
printf("%dn%d",num[i],num[j]);
by
printf("%d,%dn",num[i],num[j]);
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
add a comment |
The issue was not giving a new line after the first result.
replace
printf("%dn%d",num[i],num[j]);
by
printf("%d,%dn",num[i],num[j]);
The issue was not giving a new line after the first result.
replace
printf("%dn%d",num[i],num[j]);
by
printf("%d,%dn",num[i],num[j]);
answered Mar 21 at 14:51
brunobruno
11.6k31326
11.6k31326
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
add a comment |
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
Yeah,got that.Stupid mistake from my side.
– Combospirit
Mar 21 at 14:52
add a comment |
i find nothing wrong here 9+6=15
and 8+7=15
and also in printf instead of
printf("%dn%d",num[i],num[j]);
use
printf("%d %dn",num[i],num[j]);
you will get well suited output
add a comment |
i find nothing wrong here 9+6=15
and 8+7=15
and also in printf instead of
printf("%dn%d",num[i],num[j]);
use
printf("%d %dn",num[i],num[j]);
you will get well suited output
add a comment |
i find nothing wrong here 9+6=15
and 8+7=15
and also in printf instead of
printf("%dn%d",num[i],num[j]);
use
printf("%d %dn",num[i],num[j]);
you will get well suited output
i find nothing wrong here 9+6=15
and 8+7=15
and also in printf instead of
printf("%dn%d",num[i],num[j]);
use
printf("%d %dn",num[i],num[j]);
you will get well suited output
edited Mar 21 at 15:15
answered Mar 21 at 14:58
Anand YeoleAnand Yeole
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283103%2fprogram-to-find-a-pair-with-the-given-number-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
8 + 7 = 15
I don't see the issue here.– Joel Trauger
Mar 21 at 14:48