In: Computer Science
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code and results.
Below is your code: -
using System;
class MainClass {
static void Main()
{
Console.Write("Enter start value: ");
int start = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter end value: ");
int end = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter increase value: ");
int inc = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Number\t\t\tSquare\t\t\tSquareRoot");
for(int i = start; i <= end; i = i + inc) {
Console.WriteLine("{0}\t\t\t{1}\t\t\t{2}",i,i*i,Math.Sqrt(i));
}
}
}
Output
Enter start value: 3 Enter end value: 20 Enter increase value: 4 Number Square SquareRoot 3 9 1.73205080756888 7 49 2.64575131106459 11 121 3.3166247903554 15 225 3.87298334620742 19 361 4.35889894354067