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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?