static void Main(string[] args) { int year; Console.Write(«Enter the Year :»); year = Convert.ToInt32(Console.ReadLine()); if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) Console.WriteLine(«{0} is Leap Year»,year); else Console.WriteLine(«{0} is not a Leap Year»,year); Console.ReadLine(); }
Рубрика: Статьи
Программа для подсчета общего количества букв в тексте C#
static void Main(string[] args) { string myString = Console.ReadLine(); int count = 0; for (int i = 0; i < myString.Length; i++) { // check the char for whitespace. If char is not whitespace, increase the count variable if (!char.IsWhiteSpace(myString[i])) { count++; } } Console.WriteLine(«Total letters: «+ count); Console.ReadLine(); }
Программа C# для нахождения всех простых чисел в интервале
Ниже продемонстрирован код программы, которая находит все простые числа в интервале. static void Main(string[] args) { int num1, num2,sayac=0; Console.Write(«Enter lower range: «); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write(«Enter upper range: «); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(«Prime numbers between {0} and {1} are: «,num1,num2); Console.WriteLine(«==============================================»); for(int i=num1;i<num2;i++) { sayac = 0; if(i>1) { for(int j=2;j<i;j++) { if(i%j==0) { […]
Исходный код на C# конвертация долларов в центы.
Пример программы для расчета конвертации доллара в центы. static void Main(string[] args) { double dollar_amount; int cents; // int compute_cents; Console.Write(«Enter dollar amount :»); dollar_amount = Convert.ToDouble(Console.ReadLine()); cents =(int) (dollar_amount * 100); Console.WriteLine(«{0} $ = {1} ¢»,dollar_amount,cents); Console.ReadLine(); }
Исходный код программы на C# для подсчета количества слов в строке
Ниже продемонстрирован код программы, которая подсчитывает количество слов в строке. static void Main(string[] args) { string sentence; Console.Write(«Enter String : «); sentence = Console.ReadLine(); string[] words = sentence.Split(‘ ‘); Console.WriteLine(«Count of words :»+words.Length); Console.ReadKey(); }