Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (lgbasallote):

i know this is gonna sound noobish but how do you do division in C? i believe c = a/b produces just the whole number and not the decimal or something

OpenStudy (anonymous):

It would be convenient to assign c as double or float (dynamic initialization) (provided a and b are already assigned). double c=a/b;

OpenStudy (lgbasallote):

could you cite an example? as to how it would look like in a code i mean

OpenStudy (anonymous):

Well what you are asking is a problem of type casting/ type conversion. This way you'll never get to learn C. There are a million possibilities of questions from a language so vast as C (Sea?). Get yourself a good book and read it from cover to cover. That will help you grasp the concept of programming and C as well. This book will suit the purpose: http://www.amazon.com/Head-First-C-David-Griffiths/dp/1449399916/ref=pd_sim_sbs_b_4 Go get it and start learning. Good Luck. _____________________________________________________________________________________ As for your answer if you divide an integer (a number without decimal value) with an integer it gives an integer. So, int a = 7 ; int b = 3; int c = (a/b) ; c will be 2, not 2.333... however you can easily type cast : float c = (2.0/3.0) ; that will give c = 2.3333.... or you can type convert int a = 7 ; int b = 3; float c =((float)a/(float)b) ; that will again give c = 2.3333.... Hope this helps. But take my advice, read any good book on introductory programming fast. As that way you'll learn several nook and crannies of coding, which you'll not learn he way you are studying now. Have a good day !

OpenStudy (lgbasallote):

if you use float then you dont use int anymore?

OpenStudy (anonymous):

@NiveditaSingh Dynamic initialization? I think you confused with assignment and casting. Also when answering something please tend to as lucid as possible. Half cooked answers only confuse beginners.

OpenStudy (anonymous):

Did not get you @lgbasallote . What do you mean?

OpenStudy (lgbasallote):

for example i have int a, b, c; if i use float do i write it as int a, b,c; float c; ??

OpenStudy (anonymous):

Wrong syntax. You would get an error like this : Conflicting types....

OpenStudy (lgbasallote):

ohh so how should it be

OpenStudy (anonymous):

simple, float c ; that's it.

OpenStudy (lgbasallote):

ahh i see thanks :) that was what i was looking for :DDD

OpenStudy (anonymous):

Welcome ! Get that book I recommended... will help you a lot !

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!