Advertisement
GraionDilach

Szumma A és B közti párosok

Oct 10th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication5
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int a;
  13.             do{
  14.                 Console.WriteLine("\nKérem az első egész számot:");
  15.                 a = int.Parse(Console.ReadLine());
  16.             } while(a <= 0);
  17.  
  18.             int b;
  19.             do
  20.             {
  21.                 Console.WriteLine("\nKérem a második egész számot:");
  22.                 b = int.Parse(Console.ReadLine());
  23.             } while (b <= 0);
  24.  
  25.             Console.WriteLine("\nKözöttük lévő páros számok összege");
  26.             if (b < a)
  27.             {
  28.                 int csere = a;
  29.                 a = b;
  30.                 b = csere;
  31.             }
  32.  
  33.             int sum = 0;
  34.  
  35.             for (a++; a != b; a++)
  36.             {
  37.                 if (a % 2 == 0)
  38.                 {
  39.                     sum += a;
  40.                 }
  41.  
  42.             }
  43.  
  44.             Console.WriteLine(sum);
  45.            
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement