+ 3
How would you do a C program
How would you do a C program that asks for two numbers and divides them and displays the result on the console but without using floating or the% f specified only int
17 odpowiedzi
+ 10
IF you just search every task of this exercise you will solve it. You have described the problem perfect.
Search for (here in sololearn) :
1. "Input in C"
2. "divide in C" (easy : number1/number2;)
3. "output in C without using %f"
Open your IDE in your profile section, click the NEW CODE button, Select as language C and write what you found in 1, 2 ,3 with this order. Click RUN and you will see the results.
+ 8
to complement blackwinter:
1. & 2. are sure to be found in c course.
3. if it is not mentioned in the c course, try search bar of q&a or google or ask here (but only if you don't find a post in q&a)
+ 6
O.k i think i have the solution (interesting)
For example you have 10 and 3.
you do 10/3=3. Then you do 10%3=1=mod. printf(3).
Now you do: mod*10/3=3, (mod*10)%3=1=mod , printf("."+3)
mod*10/3=3, (mod*10)%3=1=mod , printf(3)
...
Another example:
7 and 4
7/4=1 you print 1.
7%4=3 , 3*10/4=7 you print "." + 7.
(3*10)%4=2, 2*10/4=5 you print 5.
(2*10)%4=0 you stop because division is complete. (zero modulo as result)
3.75 printed.
+ 5
Have you tried?
+ 5
So you need, 10/3=3 but you need this 3.33 without using int. Are u allowed to use modulo %? 10%3=1 Are we allowed to use this ?
+ 4
123456
3.33 converted to int would be 3.
if you need 3.33 you should leave it as float
+ 4
Did you solve it?
+ 3
Maybe I should explain with an example, it would be input I have 10 and 3 the output should be 3.33 but without using float only int
+ 3
Credit to blackwinter,
https://code.sololearn.com/cBEE7tCIUomb/?ref=app
+ 2
Everything except float ni% f is allowed
+ 2
I still don't have it confusing
+ 2
Or do you simply need the quotient and integer division only?
+ 1
This is late, but I see no accepted solution yet. Did you consider using fixed point representation?
For example, if you want 3 decimal points of precision, multiply the input integer values by 1000 in order to shift them to the left by 3 decimal places. Then use integer division. Process the output as needed to display the decimal between the third and fourth digits from the right-hand side.
0
Have you done it
- 1
Pr
- 2
Привет