Advertisement
GraionDilach

Számtani sorozat

Feb 21st, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] DasArray = new int[10];
  13.  
  14.             bool ell;
  15.  
  16.             for (int i = 0; i < DasArray.Length; i++)
  17.             {
  18.                 do
  19.                 {
  20.                     Console.WriteLine("Kérem be a " + (i+1) + ". számot:");
  21.                     ell = int.TryParse(Console.ReadLine(), out DasArray[i]);
  22.                 }
  23.  
  24.                 while (!ell);
  25.             }
  26.  
  27.  
  28.             if (Series(DasArray))
  29.             {
  30.                 Console.WriteLine("A sorozat számtani volt.");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("A sorozat nem volt számtani.");
  35.             }
  36.  
  37.         }
  38.  
  39.         static bool Series(int[] Input)
  40.         {
  41.             int Default = Input[1] - Input[0];
  42.             for (int i = 2; i < Input.Length; i++)
  43.             {
  44.                 if (Input[i] - Input[i-1] != Default)
  45.                 {
  46.                     return false;
  47.                 }
  48.  
  49.  
  50.             }
  51.  
  52.             return true;
  53.         }
  54.  
  55.  
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement