Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views2 pages

C# Working With Text

The document contains two C# programs. The first program checks if a series of input numbers are consecutive, while the second program checks for duplicates among the input numbers. Both programs read input from the user, process the numbers, and output the results accordingly.

Uploaded by

INFRA 10'S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

C# Working With Text

The document contains two C# programs. The first program checks if a series of input numbers are consecutive, while the second program checks for duplicates among the input numbers. Both programs read input from the user, process the numbers, and output the results accordingly.

Uploaded by

INFRA 10'S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Print Consecutive numbers

using System;
using System.Collections.Generic;
using System.Linq;

namespace deepak
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter numbers");
var input = Console.ReadLine();
var numbers = new List<int>();
foreach(var number in input.Split('-'))
{
numbers.Add(Convert.ToInt32(number));
numbers.Sort();
}
var dee = true;
for(int i =1; i<numbers.Count; i++)
{
if(numbers[i] != numbers[i - 1] + 1)
{
dee = false;
break;
}
}
var message = dee ? "Consecutive" : "Not Consecutive";
Console.WriteLine(message);
}
}
}
Check duplicates in consecutive numbers
using System;
using System.Collections.Generic;
using System.Linq;

namespace deepak
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter numbers");
var input = Console.ReadLine();
if (String.IsNullOrWhiteSpace(input)){
return;
}
var numbers = new List<int>();
foreach(var number in input.Split('-'))
{
numbers.Add(Convert.ToInt32(number));
}
var unqui = new List<int>();
var dee = false;
foreach(var number in numbers)
{
if (!unqui.Contains(number))
{
unqui.Add(number);
}
else
{
dee = true;
break;
}
}
if (dee)
{
Console.WriteLine("Duplicates");
}
}
}
}

You might also like