- 2

[ASSIGNMENT] Proper division

Write a program to find the division of two numbers using scanf command. Use proper data format that gives exact answers. For example 6/3=2, while 6/4 = 1.5 and so on?C program #include <stdio.h> int main() { float a,b,division; printf("enter value of a"); scanf("%d",&a); printf("enter value of b"); scanf("%d",&b); division=(a/b); printf("%.2d",division); return 0; } doesnt work....

1st Apr 2018, 8:33 AM
Jordan
Jordan  - avatar
2 Answers
+ 5
Your scanf call used %d which was supposedly for integers, use %f for float values and it will work : ) int main() { float a,b,division; printf("Enter value of a: "); scanf("%f",&a); printf("%.2f\nEnter value of b: ", a); scanf("%f",&b); division=(a/b); printf("%.2f\nDivision result: %.2f", b, division); return 0; } Hth, cmiiw
1st Apr 2018, 9:21 AM
Ipang
0
Error..... it is working on code sololearn but doesnt work on dev c++..
2nd Apr 2018, 7:04 PM
Jordan
Jordan  - avatar