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?













-2















#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.










share|improve this question



















  • 1





    8 + 7 = 15 I don't see the issue here.

    – Joel Trauger
    Mar 21 at 14:48















-2















#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.










share|improve this question



















  • 1





    8 + 7 = 15 I don't see the issue here.

    – Joel Trauger
    Mar 21 at 14:48













-2












-2








-2








#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.










share|improve this question
















#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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












2 Answers
2






active

oldest

votes


















3















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]);





share|improve this answer























  • Yeah,got that.Stupid mistake from my side.

    – Combospirit
    Mar 21 at 14:52


















0














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






share|improve this answer
























    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
    );



    );













    draft saved

    draft discarded


















    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









    3















    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]);





    share|improve this answer























    • Yeah,got that.Stupid mistake from my side.

      – Combospirit
      Mar 21 at 14:52















    3















    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]);





    share|improve this answer























    • Yeah,got that.Stupid mistake from my side.

      – Combospirit
      Mar 21 at 14:52













    3












    3








    3








    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]);





    share|improve this answer














    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]);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • 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













    0














    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






    share|improve this answer





























      0














      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






      share|improve this answer



























        0












        0








        0







        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






        share|improve this answer















        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 21 at 15:15

























        answered Mar 21 at 14:58









        Anand YeoleAnand Yeole

        11




        11



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript