Print the values from 30 to 3000..
But not allowed Ascending order like this .. 123,234,354,657, 789 and Descending order like this .. 987,654,432,321 ... Using c# code..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upendra Pratap ShahiPosted Jul 22, 2015, 5:41 AM
Hello Raja A,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NumberCheck.aspx.cs" Inherits="NumberCheck" %>
DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>title>
head>
<body>
<form id="form1" runat="server">
<div>
div>
form>
body>
html>
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NumberCheck : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Printnumber();
}
protected void Printnumber()
{
for (int i = 30; i <= 3000; i++)
{
if (i.ToString().Length > 1)
{
if (!test.IsConsecutiveThroughLinq(i.ToString()))
{
Response.Write(i + "
");
}
else
{
Response.Write("
");
}
}
}
}
}
static class test
{
public static bool IsConsecutiveThroughLoops(this string value)
{
var digits = value.ToString().ToList();
var differences = new List<Int32>();
for (int i = 0; i < digits.Count; i++)
{
if (i != digits.Count - 1) // not the last number
{
var difference = digits[i] - digits[i + 1]; // subtract the current digit from the next digit
differences.Add(difference);
}
}
// consecutive numbers will always have the same difference and that difference must be -1 or 1 (immediate)
if (differences.Distinct().Count() == 1 && (differences.First() == 1 || differences.First() == -1))
{
return true;
}
return false;
}
}
Govinda Rajulu YemineniPosted Jul 22, 2015, 6:14 AM
Upendra Pratap ShahiPosted Jul 22, 2015, 6:13 AM
Raja APosted Jul 22, 2015, 6:11 AM
Upendra Pratap ShahiPosted Jul 22, 2015, 6:00 AM
Govinda Rajulu YemineniPosted Jul 22, 2015, 5:55 AM