97.7k views
4 votes
Write a C# program named InchesToCentimeters that declares a named constant that holds the number of centimeters in an inch: 2.54. Also declare a variable to represent a measurement in inches, and assign a value. Display the measurement in both inches and centimeters—for example, if inches is set to 3, the output should be: 3 inches is 7.62 centimeters.

1 Answer

5 votes

Answer:

// program in C#.

using System;

// class definition

class InchesToCentimeters

{

// main method of the class

public static void Main (string[] args)

{

// variable

int inches=3;

const double centimeters=2.54;

// find the centimeters in 3 inches

double result=inches*centimeters;

// print the centimeters in 3 inches

Console.WriteLine("{0} inches is {1} centimeters",inches,result);

}

}

Step-by-step explanation:

Declare and initialize "inches=3".Then declare a constant variable "centimeters" and initialize it with "2.54".Then find the centimeters in 3 inches and print the value.

Output:

3 inches is 7.62 centimeters

User Jodonnell
by
4.9k points