| You are here: | About>Computing & Technology>C / C++ / C#> C> C Tutorials> Some Arithmetic Operations |
![]() | C / C++ / C# |
Elsewhere on the WebC Tutorial Lesson Two - Handling NumbersLearn about Arithmetic OperationsWriting 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 2Three int variables are declared. A and B are assigned values, then total is assigned the sum of A and B.
Before running this exampleHere'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 OperationsAs 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.
Elsewhere on the Web |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our 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. |



