Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
this is my first post so excuse me if I am not being clear enough.
As the title says I want to split a number into smaller parts, for example 1998 to 1,9,9,8. I have looked around but I am stuck trying to figure out the right term to search for.
Reason why I want this done is to later multiply every other number with either 1 or 2 to be able to examine whether it's correct or not.
Sorry I can't provide any code because I am not sure how I should tackle this problem.
As #mjwills said, mod is what you want.
static IEnumerable<int> Digitize(int num)
{
while (num > 0)
{
int digit = num % 10;
yield return digit;
num = num / 10;
}
}
And then call it like so:
static void Main(string[] _)
{
int num = 1998;
int[] digits = Digitize(num).ToArray();
Console.WriteLine($"Original: {num}");
foreach (var digit in digits)
Console.WriteLine(digit);
}
make a string of that number and make it like this
```
int a = 1990;
int[] intArray = new int[a.ToString().Length];
int index = 0;
foreach( char ch in a.ToString())
{
intArray[index] = int.Parse(ch.ToString());
index++;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
In the below code i have declared an and then assigned it to z. [Please note this is a duplicate]
double an;
for(double z= Amt+Intrest; z>0; z-=MonthlyInstallment)
{
an = z;
}
I want to access the an variable in the below loop.
for (int i = 0; i < Months; i++)
{
dt.Rows.Add(i + 1, MonthlyInstallment, MonthlyIntrest, MonthlyInstallment - MonthlyIntrest,//use the an variable here);
}
You cannot relate the two loops directly, because I assume that those have equal iterations.
A suggestion: You could calculate the value a the loop.
// start with the base value.
double an = Amt + Intrest;
for (int i = 0; i < Months; i++)
{
dt.Rows.Add(i + 1, MonthlyInstallment, MonthlyIntrest, MonthlyInstallment -MonthlyIntrest, an);
// decrease an with the MonthlyInstallment
an = an - MonthlyInstallment;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
the question with image
This is my code and I explained everything in the code.
Console.Write("If you write stop program will stop.");
string a;
string b = "stop";
a=Console.ReadLine(); //I try to get a value for my a string
for (int i = -3; i <= a.Length; i+=4) // try to read them with 4 length groups
{
if (a[i] == b) //and my logic was like this if it see the stop it will stop but I couldn't write it.
{
}
}
Within your function (I suppose it's the application entry point):
while (true)
{
String line = Console.ReadLine();
if ((line == null) || (line.ToLowerInvariant() == "stop"))
break;
// implement your logic here... for example, if you want to print
// a word at once even if the user entered multiples:
String[] split = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (Int32 i = 0 ; i < split.Length; ++i)
Console.WriteLine(split[i]);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Currently, I am trying to convert coffee script from there https://github.com/slang800/instagram-id-to-url-segment to C# but I am unable to convert because I have less exp in coffee script. What I need to do is simple but I am unable to guess the algo. If id is 1038059720608660215 then value should be 5n7dDmhTr3. The complete code of algo is available at github.
Try this
static void Main(string[] args)
{
string[] convert = {
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","a","b","c","d",
"e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x",
"y","z","0","1","2","3","4","5","6","7",
"8","9","-","_"
};
Int64 input = 1038059720608660215;
string output = "";
for (int i = 9; i >= 0; i--)
{
long digit = (input >> (6 * i)) & 0x3F;
output += convert[digit];
}
Console.WriteLine(output);
Console.ReadLine();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
im trying to make a song in beeps with pi and i need to delet the dot (pi1[1]) () and i need to convert the char array pi1 to int array pi2 (*)
double a = Math.PI;
string b=a.ToString();
char[] pi1 = b.ToCharArray();
* pi1[1] = '0';
int[] pi2;
for (int i = 0; i < pi1.Length; i++)
{
** pi2[i] = int.Parse(pi1[i].ToString());
}
//for (int i = 0; i > 40; i++)
//{
// Console.Beep(100*c, 100);
//}
The part that seems to be causing the problem is the need to not try to convert the decimal point. You can do this using string.Replace.
The following is a one-line solution to get the first 15 digits of pi as an array of integers:
int[] piDigits = Math.PI.ToString()
.Replace(".", "")
.Select(c => c - '0')
.ToArray();
Assuming that pi1 consists entirely of the characters 0–9, you could parse it into an int array using:
int[] pi2 = pi1.Select(c => c - '0').ToArray();