Advertisement
GraionDilach

Növekvő számsorozat meghatározása alfüggvénnyel

Nov 14th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication11
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             int[] array = new int[10];
  14.  
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 Console.Write("Kérem az " + (i + 1) + ". elemet: ");
  18.                 array[i] = int.Parse(Console.ReadLine());
  19.             }
  20.  
  21.             if (szamtan(array))
  22.             {
  23.                 Console.WriteLine("A tömb növekvő számtani sorozatot alkot.");
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("A tömb nem alkot növekvő számtani sorozatot.");
  28.             }
  29.  
  30.  
  31.         }
  32.  
  33.         static bool szamtan(int[] tomb)
  34.         {
  35.             int kul = tomb[1]-tomb[0];
  36.             bool ell = true;
  37.             if (kul < 0) { ell = false; }
  38.  
  39.             for (int i = 2; i < tomb.Length && ell; i++)
  40.             {
  41.                 if (tomb[i] - tomb[i-1] != kul)
  42.                 {
  43.                     ell = false;
  44.                 }
  45.             }
  46.             return ell;
  47.         }
  48.  
  49.     }
  50. }
  51.  
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement