Advertisement
Hazem3529

sum with swap

Mar 21st, 2015
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApplication1
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {   // the range [x,y] closed
  8.             int x = Convert.ToInt32(Console.ReadLine());
  9.             int y = Convert.ToInt32(Console.ReadLine());
  10.             int sum =0; // will carry the sum :3 declared out side loop scoop with value = 0
  11.        
  12.            
  13.          
  14.          
  15.  
  16.  
  17.             while (x <= y) { //removed 5 we 7atet y as max range
  18.                //simple sum
  19.                 sum = sum + x;
  20.                 // the increment to make the loop end
  21.                 x++;
  22.             }
  23.             //the answer out side the loop
  24.             Console.WriteLine("the sum is : {0}", sum);
  25.            
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement