If the input is 6789 the output should be 6,7,8,9,67,78,89,678,789,6789
The logic should work for large numbers Like 67890,12345678 etc
static Int64 substrings(string n)
{
string p = string.Empty, q = string.Empty, r = string.Empty;
char[] c = n.ToCharArray();
string s = string.Empty;
Int64 res = 0;
for (int x = 0; x < n.Length; x++)
{
res += Convert.ToInt64(n[x].ToString());
}
for (int x = 0; x < n.Length; x++)
{
if (x > 0)
{
p = n[x - 1].ToString();
q = n[x].ToString();
r = p + "" + q;
p = q;
q = r[0].ToString();
res += Convert.ToInt64(r);
}
}
for(int x = 0; x < n.Length; x++)
{
if (n.Length > 2)
{
s += n[x];
}
}
if (n.Length > 2)
{
return res + Convert.ToInt64(s);
}
else
{
return res;
}
}
This is the code I have written for generating substrings. This logic doesn't work large numbers