Академический Документы
Профессиональный Документы
Культура Документы
namespace CSharp1Exercises.ControlFlow
/// <summary>
/// Write a program to count how many numbers between 1 and 100 are divisible by 3 with no
remainder.
/// </summary>
var count = 0;
if (i%3 == 0)
count++;
/// <summary>
/// Write a program and continuously ask the user to enter a number. The loop terminates when
the user
/// enters “ok". Calculate the sum of all the previously entered numbers and display it on the
console.
/// </summary>
{
var sum = 0;
while (true)
if (input.ToLower() == "ok")
break;
sum += Convert.ToInt32(input);
/// <summary>
/// Write a program which takes a single argument from the console, computes the factorial and
prints the
/// value on the console. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2
x1
/// </summary>
var factorial = 1;
factorial *= i;
Console.WriteLine("{0}! = {1}", number, factorial);
/// <summary>
/// Write a program that picks a random number between 1 and 10. Give the user 4 chances to
guess the number.
/// If the user guesses the number, display “You won". Otherwise, display “You lost".
/// </summary>
if (guess == number)
Console.WriteLine("You won!");
return;
Console.WriteLine("You lost!");
}
/// <summary>
/// Write a program and ask the user to enter a series of numbers separated by comma. Find the
maximum of the
/// numbers and display it on the result. For example, if the user enters “5, 3, 8, 1, 4", the program
should
/// </summary>
max = number;