1. ## C Math Problem

Hello guys,
I need some help on solving this math problem in c.

result=3+-(4)/2

result variable = 3 plus minus (4) divided by 2.
thanks,

PUNJABIAN263  Reply With Quote

2. Ok, We have x=3+-4/2

Since you have to follow the order of operations, you have to divide the -4 by the positive 2. so x=3+-2

Now we have to add. We have a positive three and a negative 2 so two taken from a positive 3 leaves you with a positive 1 so the answer is x=1

x=3+-4/2
x=3+-2
x=1  Reply With Quote

3. err... well this is what it would look like in C i guess:

Code:
```#include <iostream.h>

int main (void)
{
int result;
result=0;

result=3+(-4)/2;
}```
watch out for orders of operation and then output the answer!

EDIT: damn someone got there before me...cheyenne i think he wanted us to write a C program for him that did that...umm how do you output something again in C? damn i hate programming...  Reply With Quote

4. printf("%d",result);

this should work, in the shortest code possible

#include<stdio.h>
void main()
{
printf("%d",(3+(-4)/2));
}

for learing sake this is more 'programitically correct'

#include<stdio.h>
int main(int argc,char ** argv)
{

printf("%d",(3+(-4)/2));
}

oops..hit worng key before i was finished

#include<stdio.h>
int main(int argc,char ** argv)
{
int result;
result = 3+(-4)/2;
printf("%d\n",result);
return 0;
}  Reply With Quote

5. well solutions are down there...but punjabian263 what are u actually trying to achieve...and are u facing any errors in it??  Reply With Quote

6. Yea remember Bodmas when doing maths. Both on computer and by hand

B do anything in brackets first
o powers of
d division
m Mulitplication
s subtraction

if you run though that list when you solve a problem its makes it work,

i2c  Reply With Quote

7. Actually, it's BEDMAS.

Brackets
Exponents
Division
Multiplication
Subtraction  Reply With Quote

8. well actually, you are all wrong, it is PEMDAS:

P-Parenthesis
E-Exponents
M-Multiplication
D-Division
S-Subtraction

This just proves that there are multipule different ways how to remember the order of operations...anyways just thought i might share how my seventh grade teacher thought them to us   Reply With Quote

9. heheh there must be load of different ways to do it,

Last year i did first year degree level maths and it worked for me, and its worked for me for the past 8 or 9 yrs

looks like theres a british, american and canadian way!

i2c  Reply With Quote

10. ## Thanks to all

Hello all guys,
Thanks for helping me.
my problem is solved. i have got the right answer.

THANKS,

punjabian263  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•