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
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
int a,b,c,d;
float x,y,z;
printf("enter the a,b,c,d value");
scanf("%d%d%d%d",&a&b&c&d);
x=a/b;
y=c/d;
z=x+y;
printf("value of z is %2f",z);
getch();
}
#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
#include<stdio.h>
void main()
{
int a,b,c,d,x,y;
float ans;
printf("Enter a and b values:");
scanf("%d %d",&a,&b);
printf("Enter c and d value:");
scanf(%d %d",&c,&d);
x=(float)a/b;
y=(float)c/d;
ans=x+y;
printf("The final answer is %d",ans);
getch();
}
#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;
}
/* program to solve the following expression: (a/b) + (c/d) The values of a, b, c and d are taken as input from the user.using typecasting to perform real division*/
#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;
}
#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;
}
Login to add comment