Richards
reverse
So im trying to reverse array random numbers, but it keeps giving wrong output, so i have 10 array and 10 random numbers but when i try to reverse it gives me 10 arrays, but worst part is it doesnt start from 0 but from 10, before it shows all 0 and only then result is reversed
Random rand = new Random(20);
int[] array = new int[20];
for (int i = 0; i < 10; i++)
{
int x = rand.Next(20);
array[i] = x;
Console.WriteLine($"Mas[{i + 1}] = {x}");
}
Array.Reverse(array);
// Display the reversed array
Console.WriteLine("Reversed array:");
for (int i = 1; i < array.Length; i++)
{
Console.WriteLine($"Mas[{i + 1}] = {array[i]}");
}
3 replies
No inbuilt functions
Hello, im a year 1 student so my knowledge is not that massive.
So i have this task for university where we have to do multiple steps without using inbuilt functions except length
so my question is, are there any ways to change from lowercase to uppercase without ToUpper, and how to split row1 user text in half and put row2 text in middle of row1.
Thanks in advance if anyone
14 replies
✅ loop do while
static void Main(string[] args)
{
int number;
Console.WriteLine("Ievadiet skaitli R:");
number = Convert.ToInt32(Console.ReadLine());
int cipars = number;
int skaitlis;
Console.WriteLine("Ievadiet pirmo skaitli:");
skaitlis = Convert.ToInt32(Console.ReadLine());
do
{
Console.WriteLine("Reiz[" + number + "] = ");
number++;
}
while (number<=cipars);
}
So i have to do loop which starts from 0 to number i entered, for example i enter 6 it should print 0 1 2 3 4 5 6, but i either get it so it starts from 6 or, it goes endlessly, anyone knows what to write in the while section so that it starts from 0 till the number entered
6 replies
❔ factorial using equation
So i am stuck on this task where i have to also use equation for example
11 =1
12=2
23=6
and i still don't get the for cycles/loops so im struggling on finish product, i have almost everything except the 1st number which is last factorials anserw.
as of right now it is
11=1
22=2
63=6
here is the code i have right now, it has mistakes i know but im learning.
static void Main(string[] args)
{
Console.WriteLine("Please enter your number: ");
int n = int.Parse(Console.ReadLine());
int factorial = 1;
int factorialres = 1;
for (int i = 1; i <= n; i++)
{
factorial = i;
factorialres = factorial;
Console.WriteLine(factorialres + "" + i + " = " +factorial);
}
}
3 replies