Horje
consecutive numbers c# Code Example
consecutive numbers c#
namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter numbers separate by hypen : ");
            var name = Console.ReadLine();
            var numarray = name.Split('-');
            for (var i = 0;i<=numarray.Length-1;i++ )
            {
                if (i>1 && (Convert.ToInt32(numarray[i]) != Convert.ToInt32(numarray[i - 1])+1))
                {
                    Console.WriteLine("Not Consecutive");
                    break;
                }
                if (i == numarray.Length-1)
                {
                    Console.WriteLine("Consecutive");
                }

            }
        }
    }
}
consecutive numbers c#

using System;

namespace ConsoleApp7
{
    public class Program
    {
        public static void Main(string[] args)
        {
        Console.WriteLine("Enter numbers separate by hypen : ");
        var name = Console.ReadLine();
        var numarray = name.Split('-');
        int firstValue = Convert.ToInt32(numarray[0]);

        bool cons = true;
        for (var i = 0;i<numarray.Length;i++ )
        {
            if (Convert.ToInt32(numarray[i])-i != firstValue)
            {
                cons = false;                   
                break;
            }
        }
        if (cons)
        {
            Console.WriteLine("Consecutive");
        }
        else
        {
            Console.WriteLine("Not Consecutive");
        }
    }
}





Csharp

Related
multiplication using arrays Code Example multiplication using arrays Code Example
change vignette intensity unity Code Example change vignette intensity unity Code Example
meta keywords tag mvc .net core Code Example meta keywords tag mvc .net core Code Example
Create gaps / headers between variables in the unity inspector Code Example Create gaps / headers between variables in the unity inspector Code Example
How to get the world position of the edge of an object? Code Example How to get the world position of the edge of an object? Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13