- Related Questions & Answers
- Selected Reading
C program to perform addition, subtraction, multiplication & division. To perform addition, subtraction, multiplication and division of any two number in C Programming, you have to ask to the user to enter two number and then ask to enter the operator to perform the particular mathematical operation and display the result. Instead of adding, you can also have the program subtract, divide, and multiply. You can do anything you want, really; this is just a simple math function in C. Now, I am going to show you how to use a math function in Dev-C. For this, we only need one variable. I also need to create an alphabetical value.
C++ProgrammingServer Side Programming
Average of numbers is calculated by adding all the numbers and then dividing the sum by count of numbers available.
An example of this is as follows.
A program that calculates average of numbers using arrays is as follows.
Example
Output
In the above program, the numbers whose average is needed are stored in an array num[]. First the size of the array is found. This is done as shown below −
Now a for loop is started from 0 to n-1. This loop adds all the elements of the array. The code snippet demonstrating this is as follows.
The average of the numbers is obtained by dividing the sum by n i.e amount of numbers. This is shown below −
How To Divide In Dev C 4
Finally the average is displayed. This is given as follows.
I am new to C++, but I have some knowledge in Java.
What my program does is, the program asks the user two numbers. The user could only select, one, two, or zero. Then the user would select an arithmetic operator: plus, minus, times, divide. I figured everything out except the division part.
When the user select one divide by two, the answer should come out as 0.5, but it comes out as 0. All three variables are int values, so I would need to convert them into a float or a double. But how would I cast them? I've tried doing this, float(number1), and many more similar to that, but it wouldn't work.
What my program does is, the program asks the user two numbers. The user could only select, one, two, or zero. Then the user would select an arithmetic operator: plus, minus, times, divide. I figured everything out except the division part.
When the user select one divide by two, the answer should come out as 0.5, but it comes out as 0. All three variables are int values, so I would need to convert them into a float or a double. But how would I cast them? I've tried doing this, float(number1), and many more similar to that, but it wouldn't work.
Thanks,
Sam
Sam
How To Divide In Dev C Online
Edited by chudapati09: n/a
- 2 Contributors
- forum 5 Replies
- 6,636 Views
- 3 Weeks Discussion Span
- commentLatest Postby Stefano MtangooLatest Post
How To Divide In C
Stefano Mtangoo455
How To Divide In Dev C 2017
Sam,
dividing integers truncates the decimal part, one or both of them should be float/double depending on precision of data.
dividing integers truncates the decimal part, one or both of them should be float/double depending on precision of data.