PLEASE HELP ME ! PLEASE

Discussion in 'C Programming' started by vubaboota, Jun 5, 2007.

  1. vubaboota

    vubaboota Guest

    I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    Q1:
    Write a program using malloc function. In which you take input from
    user and allocate memory equal to square of this number. Which
    multiply numbers and draw a table in the following format?

    Hint: User enters 3 then program allocates equal to 9 integer
    memories.

    Output:1

    Enter a single digit number:
    2
    The multiplication table of 2 is:
    1 2
    ----------------
    1| 1 2
    2| 2 4

    Output:2

    Enter a single digit number:
    4
    The multiplication table of 4 is:
    1 2 3 4
    --------------------------------
    1| 1 2 3 4
    2| 2 4 6 8
    3| 3 6 9 12
    4| 4 8 12 16


    Q:2
    Write a macros in which swap two number without using 3rd variable and
    then call
    Macro in main function.

    Hint: a=4, b=2 after swapping a=2, b=4.


    KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
    ABOVE PROBLEM
     
    vubaboota, Jun 5, 2007
    #1
    1. Advertising

  2. "vubaboota" <> schrieb im Newsbeitrag
    news:...
    >I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

    Please don't shout at us. (hint: a sentence in all capitals is considered
    shouteing in usenet)
    Seems you had a serious problem in the classroom, paying attention to your
    teacher.

    > Q1:
    > Write a program using malloc function. In which you take input from
    > user and allocate memory equal to square of this number. Which
    > multiply numbers and draw a table in the following format?
    >
    > Hint: User enters 3 then program allocates equal to 9 integer
    > memories.
    >
    > Output:1
    >
    > Enter a single digit number:
    > 2
    > The multiplication table of 2 is:
    > 1 2
    > ----------------
    > 1| 1 2
    > 2| 2 4
    >
    > Output:2
    >
    > Enter a single digit number:
    > 4
    > The multiplication table of 4 is:
    > 1 2 3 4
    > --------------------------------
    > 1| 1 2 3 4
    > 2| 2 4 6 8
    > 3| 3 6 9 12
    > 4| 4 8 12 16
    >
    >
    > Q:2
    > Write a macros in which swap two number without using 3rd variable and
    > then call
    > Macro in main function.
    >
    > Hint: a=4, b=2 after swapping a=2, b=4.
    >
    >
    > KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
    > ABOVE PROBLEM

    Try doing your homework yourself. Come back here if you have problems and
    show what you've done so far.

    Bye, Jojo
     
    Joachim Schmitz, Jun 5, 2007
    #2
    1. Advertising

  3. vubaboota

    Flash Gordon Guest

    vubaboota wrote, On 05/06/07 07:44:
    > I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    > Q1:


    <snip>

    > KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
    > ABOVE PROBLEM


    The best help anyone can give you is to tell you to attempt to do your
    own homework. Well, that and DON'T SHOUT!
    --
    Flash Gordon
     
    Flash Gordon, Jun 5, 2007
    #3
  4. On Jun 5, 1:44 am, vubaboota <> wrote:
    > I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    > Q1:
    > Write a program using malloc function. In which you take input from
    > user and allocate memory equal to square of this number. Which
    > multiply numbers and draw a table in the following format?
    >
    > Hint: User enters 3 then program allocates equal to 9 integer
    > memories.
    >
    > Output:1
    >
    > Enter a single digit number:
    > 2
    > The multiplication table of 2 is:
    > 1 2
    > ----------------
    > 1| 1 2
    > 2| 2 4
    >
    > Output:2
    >
    > Enter a single digit number:
    > 4
    > The multiplication table of 4 is:
    > 1 2 3 4
    > --------------------------------
    > 1| 1 2 3 4
    > 2| 2 4 6 8
    > 3| 3 6 9 12
    > 4| 4 8 12 16
    >
    > Q:2
    > Write a macros in which swap two number without using 3rd variable and
    > then call
    > Macro in main function.
    >
    > Hint: a=4, b=2 after swapping a=2, b=4.
    >
    > KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
    > ABOVE PROBLEM


    These problems seem relatively well described. Is there something
    you're having trouble understanding? At least start on these problems,
    yourself. That way, when you run into trouble, you can ask specific
    questions and get useful answers. I wouldn't count on anybody doing
    your homework for you.
     
    Chris Johnson, Jun 5, 2007
    #4
  5. vubaboota <> writes:
    > I HAVE SOME SERIOUS PROBLEM


    Yes, you do. Do your own homework.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 5, 2007
    #5
  6. vubaboota

    Umesh Guest

    //swapping

    #include"stdio.h"
    int main()
    {
    int a,b;
    printf("Enter values of a & b : ");
    scanf("%d%d",&a,&b);
    a=a+b; //if a=4,b=2 now a=a+b=6
    b=a-b; //now b=a-b=6-2=4
    a=a-b;//now a=6-4=2
    printf("After swapping\n a=%d \t b=%d",a,b);
    return 0;
    }

    //table (allocate memory by yourself!)
    #include"stdio.h"
    void main()
    {
    int j=1,k=1,l=1;
    int a;
    printf("Enter a single digit number: ");
    scanf("%d",&a);
    printf("\nThe multiplication table of %d is:\n",a);
    //formatting
    for(l=1;l<=a;l++)
    printf("\t%d",l);
    printf("\n");
    for(l=1;l<=8*a;l++)
    printf("-");
    printf("\n");
    //result
    while(j<=a){
    printf("%d|\t",k); //formatting
    for(int i=1;i<=a;i++)
    printf("%d\t",i*j);
    printf("\n");k++;
    j++;}
    }
     
    Umesh, Jun 5, 2007
    #6
  7. vubaboota

    Guest

    On 5 Jun, 07:44, vubaboota <> wrote:
    > I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C


    First point - don't type in CAPITALS. It is taken as SHOUTING and is
    impolite. Many people will choose to ignore your post, or killfile you
    (ensure that they don't see anything your post again).

    Second point - this newsgroup is not "comp.lang.c.do.my.homework". We
    are not here to make up for your lack of attention in class, your
    unwillingness to approach your teacher for assistance or your complete
    incompetence. If you are learning, you have to make some effort
    yourself - write some initial attempts at solving the problems set,
    and then you can, politely, ask the group for assistance when you
    encounter difficulties with what _you_ have written.

    > Q1:
    > Write a program using malloc function. In which you take input from
    > user and allocate memory equal to square of this number. Which
    > multiply numbers and draw a table in the following format?


    Odd english in the question, but still it's fairly clear what is
    required.

    How would you get input from the user? (Hint: I'd recommend not using
    scanf()).
    How do you convert the input to a numeric?
    How would you square the number?

    Producing the output is trivial, surely. A loop to do the headings,
    followed by a loop, with a nested loop for each row.

    What have you tried? What problem did you encounter?

    >
    > Hint: User enters 3 then program allocates equal to 9 integer
    > memories.
    >
    > Output:1
    >
    > Enter a single digit number:
    > 2
    > The multiplication table of 2 is:
    > 1 2
    > ----------------
    > 1| 1 2
    > 2| 2 4
    >
    > Output:2
    >
    > Enter a single digit number:
    > 4
    > The multiplication table of 4 is:
    > 1 2 3 4
    > --------------------------------
    > 1| 1 2 3 4
    > 2| 2 4 6 8
    > 3| 3 6 9 12
    > 4| 4 8 12 16
    >
    > Q:2
    > Write a macros in which swap two number without using 3rd variable and
    > then call
    > Macro in main function.
    >
    > Hint: a=4, b=2 after swapping a=2, b=4.


    This was recently discussed in the group - a Google search would find
    the discussion. It may also be discussed in the FAQ (Frequently Asked
    Questions) at c-faq.com - it's so completely pointless and irrelevant
    a task to what I do, that I haven't looked. I seem to recall the trick
    involves XOR and I also seem to recall that there are shortcomings to
    it, but as I say, I haven't spent a lot of time or energy on looking
    into it.
     
    , Jun 5, 2007
    #7
  8. vubaboota

    Chris Dollin Guest

    Umesh wrote:

    > int a,b;


    > a=a+b; //if a=4,b=2 now a=a+b=6
    > b=a-b; //now b=a-b=6-2=4
    > a=a-b;//now a=6-4=2


    Pointless pointless ungeneralisable pointless trickery, with the nice
    possibility for undefined behaviour pointlessly thrown in for "free".

    Now you've seen it, (a) never use it [1], (b) work out three ways why
    it's a bad idea, (c) never use it.

    [1] Unless there are utterly overwhelming reasons why you must; if there
    ever are, come back here & tell us about them.

    --
    Is it a bird? It is a plane? No, it's: http://hpl.hp.com/conferences/juc2007/
    WARNING. Various parts of this product may be more than one billion years old.

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN
     
    Chris Dollin, Jun 5, 2007
    #8
  9. vubaboota

    Guru Jois Guest

    On Jun 5, 1:17 am, Umesh <> wrote:
    > //swapping
    >
    > #include"stdio.h"
    > int main()
    > {
    > int a,b;
    > printf("Enter values of a & b : ");
    > scanf("%d%d",&a,&b);
    > a=a+b; //if a=4,b=2 now a=a+b=6
    > b=a-b; //now b=a-b=6-2=4
    > a=a-b;//now a=6-4=2
    > printf("After swapping\n a=%d \t b=%d",a,b);
    > return 0;
    >
    > }
    >
    >
    >

    a^=b^=a; // could be still better than 3 statements.

    But anyway Mr Umesh don't spoon feed askers. Don't think that we don't
    know the answer, all are denying the answer to make these lazy asker
    self-dependents.

    Bye
    Guru Jois
     
    Guru Jois, Jun 5, 2007
    #9
  10. Umesh wrote:
    > //swapping
    >
    > #include"stdio.h"

    ^^^^^^^^^
    Unless you have your own private version of stdio.h, you should use the
    standard header <stdio.h>.

    > int main()
    > {
    > int a,b;
    > printf("Enter values of a & b : ");
    > scanf("%d%d",&a,&b);
    > a=a+b; //if a=4,b=2 now a=a+b=6


    // style comments in posted code is a bad idea. // style comments for
    any pre-C99 compiler are just plain wrong.

    This is very, very bad.
    1) Suppose a+b > INT_MAX. What do you think your code will do?
    2) The OP wrote "Write a macros in which swap two number without using
    3rd variable". What makes you think all numbers are ints?
    3) This is not a macro.

    The worst thing, of course, is not your program but the inane question.
    The correct answer is "don't do that; don't even try."

    > b=a-b; //now b=a-b=6-2=4
    > a=a-b;//now a=6-4=2
    > printf("After swapping\n a=%d \t b=%d",a,b);
    > return 0;
    > }
    >
    > //table (allocate memory by yourself!)


    That's fair. Leave something for him to do himself.

    > #include"stdio.h"

    ^^^^^^^^^
    see above

    > void main()

    ^^^^
    This is silly. main returns an int in a hosted environment. There has
    never been a standard for C in which main was defined as returning void.

    > {
    > int j=1,k=1,l=1;
    > int a;
    > printf("Enter a single digit number: ");
    > scanf("%d",&a);


    Quite apart from the highly vulnerable form of input, with no error
    checking, the above needs a fflush(stdout); after the prompt. I/O on
    stdin and stdout need not be synchronous.

    Note that a is not checked for being a single-digit number.

    > printf("\nThe multiplication table of %d is:\n",a);
    > //formatting
    > for(l=1;l<=a;l++)
    > printf("\t%d",l);

    ^^
    *Never* use '\t' in output designed to be read by humans. Display
    devices can interpret '\t' is widely differing ways and you have no idea
    when you are writing your program what '\t' will end up as on output.

    > printf("\n");
    > for(l=1;l<=8*a;l++)

    ^^
    You pulled that '8' out of empty air. You have no reason to expect
    that 8 is an appropriate choice.

    > printf("-");
    > printf("\n");
    > //result
    > while(j<=a){


    Don't rely on the initialization at the top of the block here. The
    for(;;) construct is a much better approach.

    > printf("%d|\t",k); //formatting

    ^^
    'k' is a superfluous variable. There is no information associated
    with k not already present in the variable 'j'.

    > for(int i=1;i<=a;i++)

    ^^^
    This is illegal for pre-C99 compilers. For C99 compilers, it creates
    a needless confusion by shadowing the already declared 'i' with block scope.

    > printf("%d\t",i*j);
    > printf("\n");k++;
    > j++;}
    > }


    To the original poster: If you turn in "Umesh"'s code, you will get the
    grade you deserve. You will not like it.
     
    Martin Ambuhl, Jun 5, 2007
    #10
  11. Guru Jois wrote:

    > a^=b^=a; // could be still better than 3 statements.


    No, it is horrid. The OP poster asked about swapping two number [sic].
    The '^' operator requires operands of an integer type. And that's not
    all that's wrong with it. This question has been beaten to death
    before. If you really are committed to the silly XOR trick, check the
    FAQ and the newsgroup archives to find out why you shouldn't be. You
    might also find out why, even when the silly XOR trick works, writing it
    as a single statement is a bad idea.
     
    Martin Ambuhl, Jun 5, 2007
    #11
  12. vubaboota

    Richard Guest

    Martin Ambuhl <> writes:

    > Guru Jois wrote:
    >
    >> a^=b^=a; // could be still better than 3 statements.

    >
    > No, it is horrid. The OP poster asked about swapping two number
    > [sic]. The '^' operator requires operands of an integer type. And


    Don't be so ridiculous. By your rationale then the numbers to be swapped
    could be different types and thus unswappable. At times it pays to maybe
    consider the context the questions are asked in and give a cautious
    reply along the lines of ...

    "assuming we are talking about unsigned integers then one way might be ...."

    > that's not all that's wrong with it. This question has been beaten to
    > death before. If you really are committed to the silly XOR trick,
    > check the FAQ and the newsgroup archives to find out why you shouldn't
    > be. You might also find out why, even when the silly XOR trick works,
    > writing it as a single statement is a bad idea.


    Students who come here asking these type of questions are rarely in the
    position to slap their lecturers.
     
    Richard, Jun 5, 2007
    #12
  13. vubaboota

    Richard Guest

    "Joachim Schmitz" <> writes:

    > "vubaboota" <> schrieb im Newsbeitrag
    > news:...
    >>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

    > Please don't shout at us. (hint: a sentence in all capitals is considered
    > shouteing in usenet)
    > Seems you had a serious problem in the classroom, paying attention to your
    > teacher.


    Is this a new record?

    14 posts.

    9 of them are discourteous warnings about posting style, homework and
    things being off topic.
     
    Richard, Jun 5, 2007
    #13
  14. "Richard" <> schrieb im Newsbeitrag
    news:...
    > "Joachim Schmitz" <> writes:
    >
    >> "vubaboota" <> schrieb im Newsbeitrag
    >> news:...
    >>>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

    >> Please don't shout at us. (hint: a sentence in all capitals is considered
    >> shouteing in usenet)
    >> Seems you had a serious problem in the classroom, paying attention to
    >> your
    >> teacher.

    >
    > Is this a new record?
    >
    > 14 posts.
    >
    > 9 of them are discourteous warnings about posting style, homework and
    > things being off topic.

    Where have I been discourteous?
    My answer was the first (according to the timestapms I can see), so why are
    you apparently atacking me for the # of posts?
     
    Joachim Schmitz, Jun 5, 2007
    #14
  15. vubaboota

    Chris Hills Guest

    In article <>, Richard <> writes
    >"Joachim Schmitz" <> writes:
    >
    >> "vubaboota" <> schrieb im Newsbeitrag
    >> news:...
    >>>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

    >> Please don't shout at us. (hint: a sentence in all capitals is considered
    >> shouteing in usenet)
    >> Seems you had a serious problem in the classroom, paying attention to your
    >> teacher.

    >
    >Is this a new record?


    No

    >14 posts.
    >9 of them are discourteous warnings about posting style, homework and
    >things being off topic.


    What has happened is we are getting far more posts of the "PLS DO MY
    HOMEWORK URGENT" type.

    These are clearly from people that use this NG as a start point without
    reading any other posts here or doing an online search first.

    Their lack of effort is therefore rewarded in kind.


    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #15
  16. vubaboota

    Chris Hills Guest

    In article <>, Martin Ambuhl
    <> writes
    >Umesh wrote:
    >> //swapping
    >> #include"stdio.h"

    > ^^^^^^^^^
    >Unless you have your own private version of stdio.h, you should use the
    >standard header <stdio.h>.


    The whole point of this code is that if the student uses it without
    understanding it they will get spotted as a CHEAT

    >To the original poster: If you turn in "Umesh"'s code, you will get
    >the grade you deserve. You will not like it.


    Correct..... If they want to cheat they have to take the consequences.
    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #16
  17. vubaboota

    Richard Guest

    Chris Hills <> writes:

    > In article <>, Richard <> writes
    >>"Joachim Schmitz" <> writes:
    >>
    >>> "vubaboota" <> schrieb im Newsbeitrag
    >>> news:...
    >>>>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    >>> Please don't shout at us. (hint: a sentence in all capitals is considered
    >>> shouteing in usenet)
    >>> Seems you had a serious problem in the classroom, paying attention to your
    >>> teacher.

    >>
    >>Is this a new record?

    >
    > No
    >
    >>14 posts.
    >>9 of them are discourteous warnings about posting style, homework and
    >>things being off topic.

    >
    > What has happened is we are getting far more posts of the "PLS DO MY
    > HOMEWORK URGENT" type.


    The why dont "we" agree that only ONE reply is enough. Why is there the
    constant feeding frenzy. Leave it alone to see if someone else replies
    or ignore it.

    >
    > These are clearly from people that use this NG as a start point
    > without reading any other posts here or doing an online search
    > first.
    >
    > Their lack of effort is therefore rewarded in kind.


    --
     
    Richard, Jun 5, 2007
    #17
  18. vubaboota

    Richard Guest

    "Joachim Schmitz" <> writes:

    > "Richard" <> schrieb im Newsbeitrag
    > news:...
    >> "Joachim Schmitz" <> writes:
    >>
    >>> "vubaboota" <> schrieb im Newsbeitrag
    >>> news:...
    >>>>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    >>> Please don't shout at us. (hint: a sentence in all capitals is considered
    >>> shouteing in usenet)
    >>> Seems you had a serious problem in the classroom, paying attention to
    >>> your
    >>> teacher.

    >>
    >> Is this a new record?
    >>
    >> 14 posts.
    >>
    >> 9 of them are discourteous warnings about posting style, homework and
    >> things being off topic.

    > Where have I been discourteous?
    > My answer was the first (according to the timestapms I can see), so why are
    > you apparently atacking me for the # of posts?


    Where did I attack you?

    And personally, I think (and I quote)

    "Seems you had a serious problem in the classroom, paying attention to
    your teacher."

    Is pretty discourteous.
     
    Richard, Jun 5, 2007
    #18
  19. vubaboota

    Guest

    On Jun 5, 12:04 pm, Richard <> wrote:
    > "Joachim Schmitz" <> writes:
    > > "vubaboota" <> schrieb im Newsbeitrag
    > >news:...
    > >>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

    > > Please don't shout at us. (hint: a sentence in all capitals is considered
    > > shouteing in usenet)
    > > Seems you had a serious problem in the classroom, paying attention to your
    > > teacher.

    >
    > Is this a new record?
    >
    > 14 posts.
    >
    > 9 of them are discourteous warnings about posting style, homework and
    > things being off topic.



    Oh please give it a break, Richard. While others on this NG
    help out giving topical answers and telling people when they
    are offtopic, you only seem to spewing out complaints about
    answers all the time. Why don't you just do like others and
    help people with C, that's what this group is for, like you say.
    Much more helpful.

    You have been told this before. And I'll just killfile you
    if you continue, just wanted to say this before that.
     
    , Jun 5, 2007
    #19
  20. vubaboota

    Richard Guest

    writes:

    > On Jun 5, 12:04 pm, Richard <> wrote:
    >> "Joachim Schmitz" <> writes:
    >> > "vubaboota" <> schrieb im Newsbeitrag
    >> >news:...
    >> >>I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
    >> > Please don't shout at us. (hint: a sentence in all capitals is considered
    >> > shouteing in usenet)
    >> > Seems you had a serious problem in the classroom, paying attention to your
    >> > teacher.

    >>
    >> Is this a new record?
    >>
    >> 14 posts.
    >>
    >> 9 of them are discourteous warnings about posting style, homework and
    >> things being off topic.

    >
    >
    > Oh please give it a break, Richard. While others on this NG
    > help out giving topical answers and telling people when they
    > are offtopic, you only seem to spewing out complaints about
    > answers all the time. Why don't you just do like others and
    > help people with C, that's what this group is for, like you say.
    > Much more helpful.



    I frequently do and have done so.

    But the pollution level in this NG is second to none. There has
    developed a policy of elitist competition between show offs and
    wannabees. I find it faintly embarrassing as well as highly
    distasteful. And it is getting worse.

    There is a big difference between being a savager of nOObs and someone
    who pleas for a bit of sanity.

    Killfile me for all I care. I really don't mind.

    I would also suggest you add posters whose net nanny to help ratio is
    more than 1:1.
     
    Richard, Jun 5, 2007
    #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. Replies:
    4
    Views:
    515
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    581
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,760
    Mike Hewson
    Jan 7, 2005
  4. mera
    Replies:
    7
    Views:
    1,111
  5. beth

    HELP HELP PLEASE HELP

    beth, Oct 27, 2005, in forum: Ruby
    Replies:
    1
    Views:
    84
    Sean O'Halpin
    Oct 27, 2005
Loading...

Share This Page