Assignments
Title
Question
How to solve the expression (a/b)+(c/d) using typecasting in c
C-and-Cpp Increment-And-Decrement-Operators 11-12 min 20-30 sec
Answers:
abc
#include <stdio.h>
int main() {
int a, b, c, d;
printf("Enter a and b: ");
scanf("%d %d", &a, &b);
printf("Enter c and d: ");
scanf("%d %d", &c, &d);
float ans = (a/b)+(c/d);
printf("Answer(without typecast) = %f\n", ans);
ans = ((float)a/b)+((float)c/d);
printf("Answer(with typecast) = %f\n", ans);
return 0;
}
Tell if there is wrong.
<font size="4">Program in c to solve the expression (a/b)+(c/d):</font>
#include <stdio.h>
int main()
{
int a,b,c,d;
float x,y,z;
printf("Enter the values of a,b,c and d:");
scanf("%d%d%d%d",&a,&b,&c,&d);
x=a/b;
y=c/d;
z=x+y;
printf("Value of x is %.2f\n",z);
x=(float)a/b;
y=(float)c/d;
z=(float)x+y;
printf("Value of x is %.2f\n",z);
return 0;
}
output:
Enter the values of a,b,c and d:3
2
1
4
Value of x is 1.00
Value of x is 1.75
Login to add comment