Ask coding questions

← Back to all posts
C# help
SebiDragu (2)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
public class Program
public static void Main(string[] args)
Console.WriteLine("Hello, world!");
public static void math1()
Console.WriteLine("Enter a number: ");
int n = Int32.Parse(Console.ReadLine());
int[] numere = new int [n];

        for(int i = 0; i <= numere.Length - 1; i++)
            n = numere[i];
            Console.WriteLine("Number of elements is " + i.ToString());
            for(int j = 0; j < i; j++)
                Console.WriteLine("Elements are: " + j);

//First I wanna type "5" for example to set 5 elements and then add them and in final I want them all to show reversed.. Can you help me please?

Answered by heyitsmarcus (325) [earned 5 cycles]
View Answer
heyitsmarcus (325)

Hi SebiDragu,

I made a repl with your code and then edited it and added comments into where I edited.

Please check out the repl link and look at the comments as to what I changed and why I changed it. If this doesn't solve your problem, please provide more clarification into what you're doing.

If this solves your problem, please mark my answer as the accepted answer.

SebiDragu (2)

@heyitsmarcus thank you! I also wanted to add manually numbers. For example (31, 23, 44, 54) and the reverse this like (54, 44, 23, 31).. that's something I couldn't understand

heyitsmarcus (325)

@SebiDragu So, you can add those numbers at any specified index that is within the realm of the integer array. Let me explain: let's say I choose the number 5 in the program. That means that numere is created with 5 indices that always start at 0. You just need to specify the index to which to assign them.

So, if you want the first one to be 31 then you would put:

numere[0] = 31;
//Set the next one to be 23
numere[1] = 23;
//And so on...up until index 4 since in this example we only created 5 indices

Or you can do this when you first create the array but you'll either want to leave off the number of indices to create or add in default values to fill the array up:

//creates numere with 4 specified indices
int[] numere = new int[] { 31, 23, 44, 54 };
//or let's create numere with n=5 (but we have to specify an additional value this time to make it 5)...the number of values specified HAS to match the length of the array
//This would generally not be good since we don't know what n would be
int[] numere = new int[n] { 31, 23, 44, 54, 0 };

I hope that makes more sense.

SebiDragu (2)

@heyitsmarcus Thank you so much, Marcus! That's exactly what I needed. I gotta do a lot of practice now.. thanks again!!

heyitsmarcus (325)

@SebiDragu You are very welcome! Good luck, and please if you have more troubles, just post on this Ask forum. I tend to check it a few times a day, and I'm sure there are other C# developers on here somewhere if I miss it. Good luck!


Can you provide the link?

  1. That isn’t a repl? 2. If you want to do simple adding why don’t you just use python and import math? It shouldn’t be that hard and I’m pretty sure that you can also reverse the number with python.