-
September 25th, 2003, 01:07 AM
#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
-
September 25th, 2003, 01:13 AM
#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
-
September 25th, 2003, 01:17 AM
#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...
Support your right to arm bears.
^^This was the first video game which i played on an old win3.1 box
-
September 25th, 2003, 01:27 AM
#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;
}
That which does not kill me makes me stronger -- Friedrich Nietzche
-
September 25th, 2003, 09:24 AM
#5
well solutions are down there...but punjabian263 what are u actually trying to achieve...and are u facing any errors in it??
guru@linux:~> who I grep -i blonde I talk; cd ~; wine; talk; touch; unzip; touch; strip; gasp; finger; mount; fsck; more; yes; gasp; umount; make clean; sleep;
-
September 25th, 2003, 11:05 AM
#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
a addition
s subtraction
if you run though that list when you solve a problem its makes it work,
i2c
-
September 25th, 2003, 03:07 PM
#7
Junior Member
Actually, it's BEDMAS.
Brackets
Exponents
Division
Multiplication
Addition
Subtraction
-
September 25th, 2003, 05:01 PM
#8
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
Support your right to arm bears.
^^This was the first video game which i played on an old win3.1 box
-
September 25th, 2003, 05:52 PM
#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
-
September 25th, 2003, 07:40 PM
#10
Thanks to all
Hello all guys,
Thanks for helping me.
my problem is solved. i have got the right answer.
THANKS,
punjabian263
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|