kvadrat4o

SumOfTwoNums

Mar 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: DVasilev
  4.  * Date: 22/03/2017
  5.  * Time: 14:14
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10.  
  11. namespace March_06SumOfTwoNumbers
  12. {
  13.     class Program
  14.     {
  15.         public static void Main(string[] args)
  16.         {
  17.             //Console.WriteLine("enter begining of the interval: ");
  18.             int beginingInterval = int.Parse(Console.ReadLine());
  19.             //Console.WriteLine("enter end of the interval: ");
  20.             int endInterval = int.Parse(Console.ReadLine());
  21.             //Console.WriteLine("enter magic number: ");
  22.             int magicNum = int.Parse(Console.ReadLine());
  23.             int sum,counter;
  24.             counter = 0;
  25.             sum=0;
  26.             for (int i = beginingInterval; i <=endInterval; i++) {
  27.                 for (int j = beginingInterval; j <=endInterval; j++) {
  28.                     sum = beginingInterval+j;
  29.                     counter++;
  30.                     if (sum==magicNum) {
  31.                         Console.WriteLine("Combination N:{0} ({1} + {2} = {3})",counter,beginingInterval,j,magicNum);
  32.                         break;
  33.                     }
  34.                     //counter++;
  35.                 }
  36.                 beginingInterval+=i;
  37.                 if (sum==magicNum) {
  38.                         break;
  39.                 }
  40.                 //counter++;
  41.             }
  42.             if(sum!=magicNum){
  43.                 Console.WriteLine("{0} combinations - neither equals {1}",counter,magicNum);  
  44.             }
  45.            
  46.             Console.Write("Press any key to continue . . . ");
  47.             Console.ReadKey(true);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment