Thread: Explain me this program.line by line and how its executed.

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    4

    Post Explain me this program.line by line and how its executed.

    Code:
    #include <stdio.h>
    int main()
     {
         double m=15.6, n=12.9;
         int x=6, y;
    
    
         x = x % (int)n;    
         printf("x=%d\n", x);
    
    
         y = m + n;    
         printf("y=%d\n", y);
    
    
         return 0;
     }
    2.
    Code:
    int main()
        {
             double x=2.5, y=4.7;
             int a=7, b;
    
    
             printf("%4.2f\n", (x + a % 3 * (int)(x+y) % 2 / 4) );
    
    
            a=2;  b=3; x=3.5; y=2.5;    
            printf("%4.2f\n", ((float)(a+b)/2 + (int)x % (int)y) );
    
    
            return 0;
        }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What trouble are you having understanding what the programs do?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    here in the first program, i am unable to understand the value of x.
    given x=x%(int)n

    hence x=0 right?

    and what does %4.2f in the second program mean?



    It'd be better if u would explain how the each line executed.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    here in the first program, i am unable to understand the value of x.
    given x=x%(int)n

    hence x=0 right?
    Explain to us how you arrived at that answer.

    and what does %4.2f in the second program mean?
    Printf format strings - Cprogramming.com
    Check out "precision" and "width" specifiers.

    It'd be better if u would explain how the each line executed.
    No, it would not be better to just give you the answer. Figuring it out on your own is how you learn, and that is in your best interest.

    Also, this looks like C code. Why is it posted on the C++ board?

  5. #5
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    hey matticus! cool down! if you know the answer , just answer it. you'd have no any losses if you just help others.yeah figuring it out is how i learn but i tried and tried and couldnt come find out why so i posted here. I wouldnt just simply post damnit!

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    hey matticus! cool down!
    ...
    I wouldnt just simply post damnit!


    you'd have no any losses if you just help others.
    You're absolutely right. That is why I come here - I use whatever time I can spare to come here and help others.

    However, doing work for you would not, by my definition, be helping. In fact, it would hinder the learning process.

    Not being able to figure something out is fine. But in order to get assistance, you should show some effort in trying to figure it out yourself.

    I don't know how much effort you've put in, but when you say, "Explain this code line by line", it appears to me that you haven't put much effort in.

    Instead, if you say, "I think it should be this for that reason, but the results aren't matching my expectations", then it would clearly show that you are indeed putting in some effort and you'd get much better responses.

    Hence the first line in my previous post. Explain how you arrived at the answer, so we can see you're trying to think it through, and we can help straighten out any problems you might be having in trying to understand the material.

  7. #7
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Why are there so many people learning programming these days that obviously don't seem to like... programming?

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Hodor View Post
    Why are there so many people learning programming these days that obviously don't seem to like... programming?
    a lot of people who don't like math still learn it. history, literature, and many other subjects are distasteful to some, but people still take the classes, usually because they're required.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    i have already got the answer thanks guys! specially matticus!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 06-07-2012, 02:50 AM
  2. Replies: 7
    Last Post: 12-13-2010, 02:13 PM
  3. Can anybody explain this line?
    By g4j31a5 in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2008, 04:59 AM
  4. why a certain line is not being executed
    By transgalactic2 in forum C Programming
    Replies: 19
    Last Post: 10-10-2008, 11:35 AM
  5. could someone explain this line to me please
    By hostensteffa in forum C Programming
    Replies: 2
    Last Post: 06-23-2002, 10:10 PM

Tags for this Thread