Float/Double Type Examples
- What will be the output of the following code fragment?
- int num1 = 1, num2 = 3, num3 = 4;
- double average = (num1 + num2 + num3) / 3;
- printf("average is %f ", average);
- What will be the output of the following code fragment?
- int num1 = 1, num2 = 3, num3 = 4;
- double average = (num1 + num2 + num3) / 3.0;
- printf("average is %f ", average);
- What will be the output of the following code fragment?
- int num1 = 1, num2 = 3, num3 = 4;
- double average = (num1 + num2 + num3) / 3;
- printf("average is %f ", average);
- What will be the output of the following code fragment?
- int num1 = 1, num2 = 3, num3 = 4;
- double average = (num1 + num2 + num3) / 3.0;
- printf("average is %.2f ", average);
- What will be the output of the following code fragment?
- double num1 = 1.0, num2 = 3.0, num3 = 4.0;
- double result = (2/5) * (num1 + num2 + num3);
- printf("result is %f ", result);
- What will be the output of the following code fragment?
- int num1 = 1, num2 = 3, num3 = 4;
- double result = (2/5.0)*(num1 + num2 + num3);
- printf("result is %.3f ", result);