plz send logic to write given program.

Discussion in 'C Programming' started by pitamber kumar, Mar 2, 2008.

  1. Write a program to find the number of and sum of all intergers greater
    than 100 & less than 200 that are divisible by 7.
     
    pitamber kumar, Mar 2, 2008
    #1
    1. Advertising

  2. pitamber kumar

    Sjouke Burry Guest

    pitamber kumar wrote:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.

    We are not supposed to do your homework.
    And dont think you will ever learn anything by cheating.
     
    Sjouke Burry, Mar 2, 2008
    #2
    1. Advertising

  3. pitamber kumar schrieb:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    i=101; while [ $i -lt 200 ]; do if [ $(($i%7)) -eq 0 ]; then echo
    $(($i/7-14)): $i; fi; i=$(($i+1)); done

    You're welcome.

    Kind regards,
    Johannes

    --
    "PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
    meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
    Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
    Rosenberg in dse <45608268$0$5719$-online.net>
     
    Johannes Bauer, Mar 2, 2008
    #3
  4. pitamber kumar

    Amandil Guest

    On Mar 2, 3:25 pm, pitamber kumar <> wrote:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    Ok, I wrote it. Now you write one yourself, post it, and I'll see how
    they compare.

    In general, do not post homework questions. If you want to hide the
    fact that it's a homework problem, show us what you have done, and
    we'll see that you're serious. We might even help you out.

    Hint: Use a loop to run through the numbers from 100 to 200. Check
    each number if it's divisible by 7: If it is, add it to a running
    total.

    -- Marty
     
    Amandil, Mar 2, 2008
    #4
  5. pitamber kumar <> writes:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    Done.

    Now it's your turn.

    (No, we will not do your homework for you.)

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Mar 2, 2008
    #5
  6. In article <>,
    Keith Thompson <> wrote:
    >pitamber kumar <> writes:
    >> Write a program to find the number of and sum of all intergers greater
    >> than 100 & less than 200 that are divisible by 7.

    >
    >Done.
    >
    >Now it's your turn.
    >
    >(No, we will not do your homework for you.)


    Actually, you just did. You just haven't published your results.
     
    Kenny McCormack, Mar 2, 2008
    #6
  7. pitamber kumar

    osmium Guest

    "pitamber kumar" writes:

    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    Look at the modulo operator. Perversely, this is represented by '%'.
     
    osmium, Mar 2, 2008
    #7
  8. pitamber kumar wrote:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    Why?
     
    Ioannis Vranos, Mar 2, 2008
    #8
  9. pitamber kumar

    santosh Guest

    pitamber kumar wrote:

    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    This is trivially easy. Show us your effort and you'll likely get good
    help. But we don't do homework on demand.
     
    santosh, Mar 2, 2008
    #9
  10. pitamber kumar

    Eric Sosman Guest

    pitamber kumar wrote:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    Here you go. Invoke it exactly as described in the
    "Usage" message, or it may misbehave.

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int main(int l,char**s){static const short o[]={23,4,5,-2,-5,-11,14,
    9,-5,1,-6,};int n,m;if(l!=2){fprintf(stderr,"Usage:\n\t%s \"Do your"
    " own homework next time, vile cheater!\"\n",*s);return EXIT_FAILURE;
    }for(m=n=puts(*++s)<0;m<(int)sizeof o;m+=sizeof(short)){n+=o[m/sizeof
    (short)];putchar(toupper((unsigned char)(n[*s])));}puts("");return 0;}
    --
    Eric Sosman
    lid
     
    Eric Sosman, Mar 2, 2008
    #10
  11. Eric Sosman schrieb:

    > Here you go. Invoke it exactly as described in the
    > "Usage" message, or it may misbehave.


    Humm, I did. It reports, after printing argv[¹]:

    XIV, MMCVII

    That's not quite the solution - am I misunderstanding something here?

    Regards,
    Johannes

    --
    "PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
    meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
    Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
    Rosenberg in dse <45608268$0$5719$-online.net>
     
    Johannes Bauer, Mar 2, 2008
    #11
  12. pitamber kumar said:

    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    We can simplify the program by making some elementary observations up
    front.

    The number of integers in the range 101 to 199 that are divisible by 7 is
    the same as the number in the range 1 to 99, although possibly there is an
    extra integer. As it happens, 98 is evenly divisible by 7, giving a
    quotient of 14, so we deduce that there are fourteen integers in the range
    1-99. The first integer in the range 101 to 199 that is divisible by 7 is
    98+7=105, and the last is 196, so we haven't managed to squeeze another
    one in there. (That doesn't happen till 301-399, in fact.)

    Now we know there are fourteen terms in this arithmetic series. Clearly
    they can be divided into seven pairs, each totalling 301, and there are
    seven such pairs, giving 2107.

    So our final C program is:

    #include <stdio.h>
    int main(void)
    {
    puts("(a) 14 (b) 2107");
    return 0;
    }

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Mar 2, 2008
    #12
  13. pitamber kumar

    Eric Sosman Guest

    Johannes Bauer wrote:
    > Eric Sosman schrieb:
    >
    >> Here you go. Invoke it exactly as described in the
    >> "Usage" message, or it may misbehave.

    >
    > Humm, I did. It reports, after printing argv[¹]:
    >
    > XIV, MMCVII
    >
    > That's not quite the solution - am I misunderstanding something here?


    Well, I may have made a misteak -- but I don't think
    I did. The output looks correct to me, if we assume the
    O.P.'s "intergers" are integers. If they're not, then I'm
    completely lost; I don't know how to deal with intergers.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Mar 2, 2008
    #13
  14. pitamber kumar wrote:
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.



    This is not a question about C. It doesn't even have anything to do
    with programming. That makes if off-topic. However, I will provide you
    with a complete answer.
    <ot>
    The first integer greater than 100 divisible by 7 is 105.
    Every one of the integers 105+7k < 200 is divisible by 7.
    for 105+7k < 200 to be true, 7k < 95, and k <= 13.
    So there are 14 such numbers for k in {0, 1, ... 13).
    This should not surprise you, since (200-100) = 100 = 14*7+2.
    The sum of these numbers is
    sum(105+7k) for k = 0, ..., 13
    which is 14*105 + 7*sum(k) for k = 0, ..., 13
    or 1470 + 7*13*14/2 = 2107

    So here is the program

    #include <stdio.h>
    int main(void)
    {
    printf("There are 14 integers greater than 100 and less than 200\n"
    "which are divisible by 7. Their sum is 2107.\n");
    return 0;
    }

    That which is easy to do analytically rarely calls for a programming
    solution.

    </ot>
     
    Martin Ambuhl, Mar 2, 2008
    #14
  15. Johannes Bauer schrieb:

    > XIV, MMCVII
    >
    > That's not quite the solution - am I misunderstanding something here?


    Yes I am! My program is broken. I didn't read the instructions throughly
    enough. Oh well. :-/

    Here it goes again:

    q=0; z=0; i=101; while [ $i -lt 200 ]; do if [ $(($i%7)) -eq 0 ]; then
    z=$(($z+$i)); q=$(($q+1)); fi; i=$(($i+1)); done; echo $q $z

    Regards,
    Johannes

    --
    "PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
    meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
    Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
    Rosenberg in dse <45608268$0$5719$-online.net>
     
    Johannes Bauer, Mar 2, 2008
    #15
  16. pitamber kumar

    Randy Howard Guest

    On Sun, 2 Mar 2008 14:25:34 -0600, pitamber kumar wrote
    (in article
    <>):

    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    I got an error when I tried to send it to you.

    It said:

    Error: Recipient incompatible with logic. Send aborted.

    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
     
    Randy Howard, Mar 2, 2008
    #16
  17. pitamber kumar

    Bartc Guest

    "Johannes Bauer" <> wrote in message
    news:...
    > Johannes Bauer schrieb:
    >
    >> XIV, MMCVII
    >>
    >> That's not quite the solution - am I misunderstanding something here?

    >
    > Yes I am! My program is broken. I didn't read the instructions throughly
    > enough. Oh well. :-/
    >
    > Here it goes again:
    >
    > q=0; z=0; i=101; while [ $i -lt 200 ]; do if [ $(($i%7)) -eq 0 ]; then
    > z=$(($z+$i)); q=$(($q+1)); fi; i=$(($i+1)); done; echo $q $z


    What language is this in? It's obviously not C, but apparently not Perl
    either.

    I had to convert to the following (with the help of a 10-min crash course in
    Perl) to get it to work:

    $q=0; $z=0; $i=101; while ( $i < 200 ) { if ( ($i%7) == 0 )
    {$z=($z+$i); $q=($q+1)}; $i=($i+1); } print $q," ",$z

    --
    Bart
     
    Bartc, Mar 2, 2008
    #17
  18. pitamber kumar

    Ian Collins Guest

    Bartc wrote:
    > "Johannes Bauer" <> wrote in message
    > news:...
    >> Johannes Bauer schrieb:
    >>
    >>> XIV, MMCVII
    >>>
    >>> That's not quite the solution - am I misunderstanding something here?

    >> Yes I am! My program is broken. I didn't read the instructions throughly
    >> enough. Oh well. :-/
    >>
    >> Here it goes again:
    >>
    >> q=0; z=0; i=101; while [ $i -lt 200 ]; do if [ $(($i%7)) -eq 0 ]; then
    >> z=$(($z+$i)); q=$(($q+1)); fi; i=$(($i+1)); done; echo $q $z

    >
    > What language is this in? It's obviously not C, but apparently not Perl
    > either.
    >

    bash/ksh shell.

    >
    > --


    Your sig is missing the trailing space after the "--"

    --
    Ian Collins.
     
    Ian Collins, Mar 3, 2008
    #18
  19. In article <j3Hyj.16868$>,
    Bartc <> wrote:
    >
    >"Johannes Bauer" <> wrote in message
    >news:...
    >> Johannes Bauer schrieb:
    >>
    >>> XIV, MMCVII
    >>>
    >>> That's not quite the solution - am I misunderstanding something here?

    >>
    >> Yes I am! My program is broken. I didn't read the instructions throughly
    >> enough. Oh well. :-/
    >>
    >> Here it goes again:
    >>
    >> q=0; z=0; i=101; while [ $i -lt 200 ]; do if [ $(($i%7)) -eq 0 ]; then
    >> z=$(($z+$i)); q=$(($q+1)); fi; i=$(($i+1)); done; echo $q $z

    >
    >What language is this in? It's obviously not C, but apparently not Perl
    >either.


    It is equally clearly not Fortran.

    Can we draw up an exhaustive list of languages that it isn't?
     
    Kenny McCormack, Mar 3, 2008
    #19
  20. pitamber kumar

    MisterE Guest

    "pitamber kumar" <> wrote in message
    news:...
    > Write a program to find the number of and sum of all intergers greater
    > than 100 & less than 200 that are divisible by 7.


    int main(int argc, char **argv)
    {
    int i,j=0;
    for (i=101;i<200;i++)
    {
    printf("Number %d\n",i);
    if (i%7==0) j+=i;
    }
    printf("Sum %d\n",j);
    }
     
    MisterE, Mar 3, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. brian

    Size of my Struct? PLZ PLZ reply

    brian, Nov 23, 2004, in forum: C Programming
    Replies:
    7
    Views:
    421
    -berlin.de
    Nov 25, 2004
  2. iskeletor
    Replies:
    3
    Views:
    364
    Barry Schwarz
    Dec 26, 2006
  3. Replies:
    1
    Views:
    386
  4. Replies:
    2
    Views:
    340
    Nick Keighley
    Nov 24, 2006
  5. Replies:
    1
    Views:
    348
Loading...

Share This Page