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
Printable View
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
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
err... well this is what it would look like in C i guess:
watch out for orders of operation and then output the answer!Code:#include <iostream.h>
int main (void)
{
int result;
result=0;
result=3+(-4)/2;
}
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...
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;
}
well solutions are down there...but punjabian263 what are u actually trying to achieve...and are u facing any errors in it??
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
a addition
s subtraction
if you run though that list when you solve a problem its makes it work,
i2c
Actually, it's BEDMAS.
Brackets
Exponents
Division
Multiplication
Addition
Subtraction
well actually, you are all wrong, it is PEMDAS:
P-Parenthesis
E-Exponents
M-Multiplication
D-Division
A-Addition
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 :)
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
Hello all guys,
Thanks for helping me.
my problem is solved. i have got the right answer.
THANKS,
punjabian263