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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현