Въведение в програмирането С#
//Write a program that reads 3 real numbers from the console and prints their sum.
using System;
class SumOf3Numbers
{
static void Main()
{
Console.WriteLine("Please write 3 numbers: ");
double numA = double.Parse(Console.ReadLine());
double numB = double.Parse(Console.ReadLine());
double numC = double.Parse(Console.ReadLine());
double sum = numA + numB + numC;
Console.WriteLine("The sum of the 3 numbers is {0}." , sum);
}
}
//Print Company Information: A company has name, address, phone number, fax number, web site and manager.
//The manager has first name, last name, age and a phone number.
//Write a program that reads the information about a company and its manager and
//prints it back on the console.
using System;
class PrintCompanyInfo
{
static void Main()
{
string companyName = "Nezabravka";
string address = "4000 Plovdiv, 2, Neven St.";
string phoneNumber = "+359 32 666 999";
string faxNumber = "+359 32 999 666";
string CompanyWebSite = "www.nezabravka.bg";
string firstName = "Ivan";
string lastName = "Ivanov";
byte managerAge = 30;
string managerPhoneNumber = "+359 888 666 999";
Console.WriteLine("The company {0} has an adress {1}, phone number {2}, fax number {3} and web site {4}. The manager of the company is {5} {6}. He is {7} years old and his phone number is {8}", companyName , address, phoneNumber, faxNumber, CompanyWebSite, firstName, lastName, managerAge, managerPhoneNumber);
}
}
//Write a program that reads the radius r of a circle and prints its perimeter and area formatted with
//2 digits after the decimal point.
using System;
class CirclePerimeterAndArea
{
static void Main()
{
Console.WriteLine("Enter the radius of a given circle: ");
double radius = double.Parse(Console.ReadLine());
double area = Math.PI * Math.Pow(radius, 2);
double perimeter =2*Math.PI * radius;
Console.WriteLine("The area of the circle is {0: 0.00} and its perimeter is {1:0.00}", area, perimeter );
}
}
//Write a program that gets two numbers from the console and prints the greater of them.
//Try to implement this without if statements.
using System;
class NumberComparer
{
static void Main()
{
Console.WriteLine("Please enter a number: ");
decimal numberA = decimal.Parse(Console.ReadLine());
Console.WriteLine("Please enter a second number: ");
decimal numberB = decimal.Parse(Console.ReadLine());
decimal number = Math.Max(numberA, numberB);
Console.WriteLine("The higher number is: {0}", number);
}
}
// Write a program that reads 3 numbers: an integer a (0 ≤ a ≤ 500),
// a floating-point b and a floating-point c and prints them in 4 virtual columns on the console. Each column should have a width of 10 characters.
// The number a should be printed in hexadecimal, left aligned; then the number a should be printed in binary form, padded with zeroes,
// then the number b should be printed with 2 digits after the decimal point,
// right aligned; the number c should be printed with 3 digits after the decimal point, left aligned.
// Examples:
// a b c result
// 254 11.6 0.5 |FE |0011111110| 11.60|0.500 |
//499 -0.5559 10000 |1F3 |0111110011| -0.56|10000 |
//0 3 -0.1234 |0 |0000000000| 3|-0.123 | */
using System;
class FormattingNumbers
{
static void Main()
{
int a=0;
double b=0;
double c=0;
do
{
Console.WriteLine("Please, enter 3 numbers : an integer a (0 ≤ a ≤ 500), a floating-point b, a floating-point c: ");
bool parseSuccess = int.TryParse(Console.ReadLine(), out a) && a >= 0 && a <= 500 &&
double.TryParse(Console.ReadLine(), out b) &&
double.TryParse(Console.ReadLine(), out c);
if (parseSuccess)
{
break;
}
else
{
Console.WriteLine("You have entered an invalid data. Please try again!");
}
} while (true);
Console.WriteLine("{0,-10}{1,-10}{2,-10}{3}", "a", "b","c","result");
Console.WriteLine("{0,-10}{1,-10}{2,-10}|{3,-10:X}|{4,-10}|{5,10:#.##}|{6,-10:0.000}|",
a, b, c, a, Convert.ToString(a, 2).PadLeft(10, '0'), b, c);
}
}
/*Write a program that reads the coefficients a, b and c of a quadratic equation
*ax2 + bx + c = 0 and solves it (prints its real roots). */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class QuadraticEquation
{
static void Main()
{
Console.WriteLine("Please enter a number for A: ");
double a = double.Parse(Console.ReadLine());
Console.WriteLine("Please enter a number for B: ");
double b = double.Parse(Console.ReadLine());
Console.WriteLine("Please enter a number for C: ");
double c = double.Parse(Console.ReadLine());
double d = (b * b) - (4 * a * c);
if (a == 0)
{
Console.WriteLine("The number A must be different from 0!");
}
else
{
if (d < 0)
{
Console.WriteLine("The discriminant is < 0 so there is no solution!");
}
else if (d > 0)
{
Console.WriteLine("Solution 1: {0}", (-b - Math.Sqrt(d)) / (2 * a));
Console.WriteLine("Solution 2: {0}", (-b + Math.Sqrt(d)) / (2 * a));
}
else
{
Console.WriteLine("The discriminant is 0 and the solution is {0}.", (-b / (2 * a)));
}
}
}
}
//Write a program that enters 5 numbers (given in a single line, separated by a space),
//calculates and prints their sum.
using System;
class SumOf5Numbers
{
static void Main()
{
Console.WriteLine("Please enter 5 single-spaced real numbers: ");
string[] input = Console.ReadLine().Split();
double a = Convert.ToDouble(input[0]);
double b = Convert.ToDouble(input[1]);
double c = Convert.ToDouble(input[2]);
double d = Convert.ToDouble(input[3]);
double e = Convert.ToDouble(input[4]);
double sum = a + b + c + d + e;
Console.WriteLine(sum);
}
}
//Write a program that reads an integer number n from the console and prints all the numbers in the interval
//[ 1 ..n ], each on a single line. Note that you may need to use a for - loop.
using System;
class NumbersFrom1toN
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
Console.WriteLine(i);
}
}
}
//Write a program that enters a number n and after that enters more n
//numbers and calculates and prints their sum. Note that you may need to use a for-loop
using System;
class SumOfNNumbers
{
static void Main()
{
Console.WriteLine("Enter a number: ");
long n = long.Parse(Console.ReadLine());
decimal sum = 0.00m;
decimal number = decimal.MinValue;
for (int i = 0; i < n; i++)
{
number = decimal.Parse(Console.ReadLine());
sum += number;
}
Console.WriteLine(sum);
}
}
//Fibonacci Numbers
using System;
class FibonacciNumbers
{
static void Main()
{
Console.Write("Enter a number: ");
int n = int.Parse(Console.ReadLine());
if (n == 1) Console.WriteLine(0);
else
{
int num1 = 0;
int num2 = 1;
Console.Write(num1 + " ");
Console.Write(num2 + " ");
int num3 = 0;
for (int i = 2; i < n; i++)
{
num3 = num1 + num2;
Console.Write(num3 + " ");
num1 = num2;
num2 = num3;
}
}
}
}
//Write a program that reads two positive integer numbers and prints
//how many numbers p exist between them such that the reminder of the division by 5 is 0.
using System;
class DividableByGivenNumber
{
static void Main()
{
Console.WriteLine("Enter first positive integer number: ");
int firstNumber = int.Parse(Console.ReadLine());
Console.WriteLine("Enter second positive integer number: ");
int secondNumber = int.Parse(Console.ReadLine());
int count = 0;
int i = 0;
for (i = firstNumber; i <= secondNumber; i++)
{
if (i % 5 == 0)
{
count++;
}
}
Console.WriteLine(count);
}
}
//Write a program that enters from the console a positive integer n and prints all the numbers
//from 1 to n, on a single line, separated by a space
using System;
class NumbersFrom1toN
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
Console.WriteLine(i);
}
}
}
//Write a program that enters from the console a positive integer n and prints all the numbers
//from 1 to n not divisible by 3 and 7, on a single line, separated by a space
using System;
class NumbersNotDivisibleBy3and7
{
static void Main()
{
Console.Write("Please enter a number N: ");
int n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
if (!(i % 7 == 0 || i % 3 == 0))
{
Console.Write("{0} ", i);
}
}
Console.WriteLine();
}
}
//Write a program that reads from the console a sequence of n integer numbers and returns the minimal,
//the maximal number, the sum and the average of all numbers (displayed with 2 digits after the decimal point).
//The input starts by the number n (alone in a line) followed by n lines, each holding an integer number.
//The output is like in the examples below
using System;
class MinMaxSumandAverageofNNumbers
{
static void Main()
{
Console.WriteLine("Please enter a sequence of n intergers: ");
int n = int.Parse(Console.ReadLine());
int min = int.MaxValue;
int max = int.MinValue;
int sum = 0;
for (int i = 0; i < n; i++)
{
int nums = int.Parse(Console.ReadLine());
if (nums < min)
{
min = nums;
}
else if (nums > max)
{
max = nums;
}
sum += nums;
}
Console.WriteLine("min = {0}",min);
Console.WriteLine("max = {0}", max);
Console.WriteLine("sum = {0}", sum);
double avg = (double)sum / n;
Console.WriteLine("avg = {0:F2}", avg);
}
}
//Write a program that reads from the console a sequence of n integer numbers and returns the minimal,
//the maximal number, the sum and the average of all numbers (displayed with 2 digits after the decimal point).
//The input starts by the number n (alone in a line) followed by n lines, each holding an integer number.
//The output is like in the examples below
using System;
class MinMaxSumandAverageofNNumbers
{
static void Main()
{
Console.WriteLine("Please enter a sequence of n intergers: ");
int n = int.Parse(Console.ReadLine());
int min = int.MaxValue;
int max = int.MinValue;
int sum = 0;
for (int i = 0; i < n; i++)
{
int nums = int.Parse(Console.ReadLine());
if (nums < min)
{
min = nums;
}
else if (nums > max)
{
max = nums;
}
sum += nums;
}
Console.WriteLine("min = {0}",min);
Console.WriteLine("max = {0}", max);
Console.WriteLine("sum = {0}", sum);
double avg = (double)sum / n;
Console.WriteLine("avg = {0:F2}", avg);
}
}
//Using loops write a program that converts an integer number to its
//binary representation. The input is entered as long. The output should be a variable of type string.
using System;
class DecimaltoBinaryNumber
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
string nbinary = null;
int r = 0;
while (n > 0)
{
r = n % 2;
n /= 2;
nbinary += r;
}
Console.WriteLine(nbinary);
string nBinary2 = null;
for (int i = nbinary.Length - 1; i >= 0; i--)
{
nBinary2 += nbinary[i];
}
Console.WriteLine(nBinary2);
}
}
//Using loops write a program that converts a hexadecimal integer number to its decimal form.
//The input is entered as string. The output should be a variable of type long
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class HexadecimaltoDecimalNumber
{
static void Main()
{
List
Binary = new List();
string Bin = Console.ReadLine();
char[] Binr = Bin.ToCharArray();
for (int i = 0; i < Binr.Length; i++)
{
Binary.Add(Binr[i]);
}
double dec = 0;
double br = Binary.Count - 1;
foreach (char item in Binary)
{
int num;
if (item == 'A' || item == 'a') num = 10;
else if (item == 'B' || item == 'b') num = 11;
else if (item == 'C' || item == 'c') num = 12;
else if (item == 'D' || item == 'd') num = 13;
else if (item == 'E' || item == 'e') num = 14;
else if (item == 'F' || item == 'f') num = 15;
else num = item - '0';
dec += num * (Math.Pow(16, br));
br--;
}
Console.WriteLine("Decimal:" + dec);
}
}
//Using loops write a program that converts an integer number to its hexadecimal representation.
//The input is entered as long. The output should be a variable of type string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class DecimaltoHexadecimalNumber
{
static void Main()
{
int number = 600;
int result = 0;
List hexNum = new List(3);
while (number % 16 > 0)
{
result = number % 16;
hexNum.Add(result);
number = number / 16;
}
hexNum.Reverse();
foreach (int num in hexNum)
{
switch (num)
{
case 1: Console.Write("1"); break;
case 2: Console.Write("2"); break;
case 3: Console.Write("3"); break;
case 4: Console.Write("4"); break;
case 5: Console.Write("5"); break;
case 6: Console.Write("6"); break;
case 7: Console.Write("7"); break;
case 8: Console.Write("8"); break;
case 9: Console.Write("9"); break;
case 10: Console.Write("A"); break;
case 11: Console.Write("B"); break;
case 12: Console.Write("C"); break;
case 13: Console.Write("D"); break;
case 14: Console.Write("E"); break;
case 15: Console.Write("F"); break;
default:
break;
}
}
}
}
//You are given n integers (given in a single line, separated by a space). Write a program that checks whether
//the product of the odd elements is equal to the product of the even elements.
//Elements are counted from 1 to n, so the first element is odd, the second is even,
using System;
class OddandEvenProduct
{
static void Main()
{
string n = Console.ReadLine();
string[] result = n.Split(' ');
int oddNums = 1;
int evenNums = 1;
for (int i = 0; i < result.Length; i++)
{
if ((i + 1) % 2 == 0)
{
evenNums *= int.Parse(result[i]);
}
else
{
oddNums *= int.Parse(result[i]);
}
}
if (oddNums == evenNums)
{
Console.WriteLine("Yes");
Console.WriteLine("product = " + oddNums);
}
else
{
Console.WriteLine("No");
Console.WriteLine("Odd product = " + oddNums);
Console.WriteLine("Even product = " + evenNums);
}
}
}
//Write a program that reads from the console a positive integer number n (1 ≤ n ≤ 20)
//and prints a matrix like in the examples below. Use two nested loops
using System;
class MatrixofNumbers
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
for (int row = 0; row < n; row++)
{
for (int col = 1; col <= n; col++)
{
Console.Write("{0,-3}", col + row);
}
Console.WriteLine();
}
}
}
//Write a program that generates and prints all possible cards from a standard deck of 52 cards (without the jokers).
//The cards should be printed using the classical notation (like 5♠, A♥, 9♣ and K♦).
//The card faces should start from 2 to A. Print each card face in its four possible suits: clubs, diamonds, hearts and spades.
//Use 2 nested for-loops and a switch-case statement.
using System;
class PrintaDeckof52Cards
{
static void Main()
{
for (int i = 2; i <= 14; i++)
{
if (i == 11)
{
Console.WriteLine("{0,4} {1,4} {2,4} {3,4}", 'J' + "" + (char)5, 'J' + "" + (char)3, 'J' + "" + (char)4, 'J' + "" + (char)6);
}
if (i == 12)
{
Console.WriteLine("{0,4} {1,4} {2,4} {3,4}", 'Q' + "" + (char)5, 'Q' + "" + (char)3, 'Q' + "" + (char)4, 'Q' + "" + (char)6);
}
if (i == 13)
{
Console.WriteLine("{0,4} {1,4} {2,4} {3,4}", 'K' + "" + (char)5, 'K' + "" + (char)3, 'K' + "" + (char)4, 'K' + "" + (char)6);
}
if (i == 14)
{
Console.WriteLine("{0,4} {1,4} {2,4} {3,4}", 'A' + "" + (char)5, 'A' + "" + (char)3, 'A' + "" + (char)4, 'A' + "" + (char)6);
}
if (i>=2 && i<=10)
{
Console.WriteLine("{0,4} {1,4} {2,4} {3,4}", i + "" + (char)5, i + "" + (char)3, i + "" + (char)4, i + "" + (char)6);
}
}
}
}
//Write a program that enters 3 integers n, min and max (min ≤ max) and prints n random numbers in the range [min...max].
using System;
class RandomNumbersinGivenRange
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
int min = int.Parse(Console.ReadLine());
int max = int.Parse(Console.ReadLine());
Random random = new Random();
for (int i = 0; i < n; i++)
{
Console.WriteLine("{0} ", random.Next(min, max));
}
}
}
Ajax info
Restful services with ajax and jquery
jquery ajax
Homework Ajax
UML diagrams
Draw ioа>
визуализацияа>
Class diagram
Sequence diagram
Use Case diagram
UML diagram
HTML form
HTML Form
HTML CSS
jQueryAccordeon
jQuery