You are here:About>Computing & Technology>C / C++ / C#> C> C Tutorials> Some Arithmetic Operations
About.comC / C++ / C#

C Tutorial Lesson Two - Handling Numbers

From David Bolton,
Your Guide to C / C++ / C#.
FREE Newsletter. Sign Up Now!

Learn about Arithmetic Operations

Writing computer software wouldn't be much use if you couldn't do addition, subtraction etc. Here's example 2.

Enter it as above and Make it.

Explanation of Example 2

Three int variables are declared. A and B are assigned values, then total is assigned the sum of A and B.

Before running this example

Here's a little tip to save time when running Command Line applications.

When you run this program from the Command Line. It should output "The number is 22".

Other Arithemetic Operations

As well as addition, you can do subtraction, multiplication and division. Just use + for addition, - for subtraction, * for multiplication and / for division.

Try changing the above program- use subtraction or multiplication. You can also change ints to floats or doubles and change %d to %f.

With floats you have no control over how many decimal points are displayed.

On the next page : Learn about output formats.

  1. All About Numbers in C
  2. More About Ints
  3. Precision Arithmetic
  4. Learn about Arithmetic Operations
  5. Specifying Output Formats in Printf
  6. Learn how to use Format Specifiers

<< Previous | Next >>

 All Topics | Email Article | Print this Page | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.