Write a function called truncate. It is passed 2 parameters, a float f and an integer d. The function truncates f so that it has d digits to the right of the decimal point. For example:
>>> truncate(line_length((0,1), (1,0)), 3)
1.414
>>> truncate(circle_circumference(1), 1)
6.2
>>> truncate(circle_area(1), 4)
3.1415
I am using c# coding to solve above problem. the following code gives output as you want.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public float Truncate(float f, int d)
{
/* local variable declaration */
float result;
result = f;
return result;
}
static void Main(string[] args)
{
float f, result;
int d;
Console.WriteLine("Enter a float value");
f = float.Parse(Console.ReadLine());
Console.WriteLine("Enter a integer value");
d = int.Parse(Console.ReadLine());
Program p = new Program();
result = p.Truncate(f, d);
string afterDecimalResult = Math.Round(result, d).ToString();
Console.WriteLine(afterDecimalResult);
Console.ReadLine();
}
}
}
Get Answers For Free
Most questions answered within 1 hours.