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

C# Working With Text

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)
31 views2 pages

C# Working With Text

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy