Advertisement
AvengersAssemble

11-10-WhileReview-HW

Oct 11th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace StamProject
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             DateTime now;
  13.             while (true)
  14.             {
  15.                 now = DateTime.Now;
  16.                 Console.WriteLine(now);
  17.                 System.Threading.Thread.Sleep(1000);
  18.                 Console.Clear();
  19.             }
  20.         }
  21.         static void PerfectNumber()
  22.         {
  23.             int num, i, check;
  24.             string calculation = null;
  25.             while (true)
  26.             {
  27.                 num = int.Parse(Console.ReadLine());
  28.                 i = num - 1;
  29.                 check = 0;
  30.                 while (i > 0)
  31.                 {
  32.                     if (num % i == 0)
  33.                     {
  34.                         if (i != 1)
  35.                         {
  36.                             calculation += i + " + ";
  37.                         }
  38.                         else
  39.                         {
  40.                             calculation += "1";
  41.                         }
  42.                         check += i;
  43.                     }
  44.                     i--;
  45.                 }
  46.                 if (num == check)
  47.                     Console.WriteLine("Number {0} is a perfect number.\n{1} = {0}", num, calculation);
  48.             }
  49.         }
  50.         static void Page151Exercise37()
  51.         {
  52.             int maxLength = 0, currentLength = 0, num1, num2 = 0;
  53.             num1 = int.Parse(Console.ReadLine());
  54.             while (num1 != 0)
  55.             {
  56.                 if (num1 > num2)
  57.                     currentLength++;
  58.                 else
  59.                     currentLength = 1;
  60.                 if (currentLength > maxLength)
  61.                     maxLength = currentLength;
  62.                 num2 = num1;
  63.                 num1 = int.Parse(Console.ReadLine());
  64.             }
  65.             Console.WriteLine("Maximum length: " + maxLength);
  66.         }
  67.         static void Page151Exercise33()
  68.         {
  69.             int countCondition = 0;
  70.             double num1, num2;
  71.             num1 = double.Parse(Console.ReadLine());
  72.             num2 = num1;
  73.             while (num1 != 0)
  74.             {
  75.                 if (num1 < num2)
  76.                     countCondition++;
  77.                 num2 = num1;
  78.                 num1 = double.Parse(Console.ReadLine());
  79.             }
  80.             Console.WriteLine("\n{0}", countCondition);
  81.         }
  82.         static void LongestDigitsSequence()
  83.         {
  84.             int num1, num2, count = 0, maxCount = 0;
  85.             num1 = int.Parse(Console.ReadLine());
  86.             num2 = num1;
  87.             while (num1 != -1)
  88.             {
  89.                 if (num1 == 0)
  90.                     num1 = 10;
  91.                 if (num1 == num2 + 1)
  92.                     count++;
  93.                 else
  94.                     count = 1;
  95.                 if (count > maxCount)
  96.                     maxCount = count;
  97.                 num2 = num1;
  98.                 num1 = int.Parse(Console.ReadLine());
  99.             }
  100.             Console.WriteLine(maxCount);
  101.         }
  102.         static void Exercise63Numbers()
  103.         {
  104.             int n, num1 = 0, num2 = int.MaxValue, middleNum = 0, difference = int.MaxValue;
  105.             string couple = null;
  106.             decimal avg, sum = 0;
  107.             n = int.Parse(Console.ReadLine());
  108.             for (int i = 0; i < n; i++)
  109.             {
  110.                 if (i != 0)
  111.                     num2 = num1;
  112.                 num1 = int.Parse(Console.ReadLine());
  113.                 if (i == Math.Floor((double)n / 2))
  114.                     middleNum = num1;
  115.                 if ((num1 - num2) < difference)
  116.                 {
  117.                     difference = num2 - num1;
  118.                     couple = num1.ToString() + " , " + num2.ToString();
  119.                 }
  120.                 sum += num1;
  121.             }
  122.             avg = sum / n;
  123.             Console.WriteLine("Average: {0}  Middle number: {1}  Smallest: {2}", avg, middleNum, couple);
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement