How can I make a calculator in C programming?

Discussion in 'C Programming' started by JOYCE, Nov 3, 2008.

  1. JOYCE

    JOYCE Guest

    Hello,
    I'm a new learner.I want to know how to make a calculator in C
    programming.
    I hope someone can help me .Thanks!
     
    JOYCE, Nov 3, 2008
    #1
    1. Advertising

  2. JOYCE

    Default User Guest

    Re: How can I make a calculator in C programming?

    JOYCE wrote:

    > Hello,
    > I'm a new learner.I want to know how to make a calculator in C
    > programming.
    > I hope someone can help me .Thanks!



    You haven't given us very much information. Thoroughly describe the
    project as you envision it, and tell us what you have already tried.




    Brian
     
    Default User, Nov 3, 2008
    #2
    1. Advertising

  3. Re: How can I make a calculator in C programming?

    On 3 Nov, 08:59, JOYCE <> wrote:

    >        I'm a new learner.I want to know how to make a calculator in C
    > programming.
    > I hope someone can help me .Thanks!


    It might be easier to start with what's called Reverse Polish
    Notation (look it up).

    Here expressions to be evaluated (calculated) are written
    like this

    2 2 + (calculates 2 + 2)
    3 4 4 + * (calculates 3 * 4 + 4)

    the rules are simple:
    Read a symbol
    if it's a number push it on a stack
    if it's an operator remove the top two items from the stack
    and apply the operator. Put the result on the stack
    When you run out of symbols print what's on the stack

    So you need a stack and a way to read symbols.

    good luck!


    --
    Nick Keighley
     
    Nick Keighley, Nov 3, 2008
    #3
  4. Re: How can I make a calculator in C programming?

    Nick Keighley wrote:


    > 3 4 4 + * (calculates 3 * 4 + 4)


    Actually this would calculate 3 * (4 + 4). This is how the stack
    looks for every symbol read ('>' prefixes a read element, '='
    prefixed a element resulting from a operation, replacing the
    elements consumed by the operation; stack grows downwards):

    >3


    3
    >4


    3
    4
    >4


    3
    4
    4
    >+ -> operator '+' performs addition on the

    two topmost elements of the stack, yielding

    3
    =8

    3
    8
    >* -> operator '*' performs multiplication on the

    two topmost elements of the stack, yielding

    =24

    Wolfgang Draxinger
    --
    E-Mail address works, Jabber: , ICQ: 134682867
     
    Wolfgang Draxinger, Nov 3, 2008
    #4
  5. JOYCE

    osmium Guest

    "JOYCE" writes:

    > I'm a new learner.I want to know how to make a calculator in C
    > programming.


    There is one in _The C Programming Language_ by Kernighan & Ritchie, fondly
    called simply K&R. Any C programmer must eventually have that book so this
    may be a good reason to get it now.
     
    osmium, Nov 3, 2008
    #5
  6. JOYCE

    mkb123

    Joined:
    Dec 28, 2011
    Messages:
    1
    Location:
    perth, Western Australia
    calculator

    hello guys am trying to write a c programme on a calculator which can calculate the following:
    i-Capacitance of capacitors in parallel (using the formular CT= C1+C2+C3....)
    ii-Capacitance of capacitors in series (using the formular 1/CT= 1/C1+1/C2+1/C3..)
    iii-Charge stored in capacitor (using the formular Q=CV)
    iv-Energy stored in capacitor (using the formular 0.5CV^2=0.5QV=0.5Q^2/C)


    the attachement is just below, can someone help me please, it will be appreciated thank you:D
     

    Attached Files:

    mkb123, Dec 28, 2011
    #6
    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. makko

    calculator

    makko, Feb 28, 2005, in forum: Perl
    Replies:
    2
    Views:
    2,960
    makko
    Mar 1, 2005
  2. Casey Hawthorne
    Replies:
    4
    Views:
    1,011
    Jarek Zgoda
    Aug 4, 2006
  3. Asim Shahzad

    How to Make Calculator in ASP and Cold fusion

    Asim Shahzad, Jan 29, 2005, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    229
    Jon Cooper
    Feb 6, 2005
  4. Asim Shahzad

    How to Make Calculator in ASP and Cold fusion

    Asim Shahzad, Jan 29, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    144
    Jon Cooper
    Feb 6, 2005
  5. sterta bole
    Replies:
    0
    Views:
    791
    sterta bole
    Aug 27, 2012
Loading...

Share This Page