جمع کردن دو آرایه و قرار دادن در یک آرایه در سی شارپ
/* * C# Program to Get 2 Arrays as Input and Produce a 3rd Array by Appending one to * other */using System;
classProgram
{
static voidMain()
{
int[] array1 = newint[5];
int[] array2 = newint[5];
int[] array3 = newint[array1.Length + array2.Length];
Console.WriteLine("Enter Any 5 Elements for the First Array :");
for (int i = 0; i < 5; i++)
{
array1[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("Enter Any 5 Elements for the Second Array :");
for (int i = 0; i < 5; i++)
{
array2[i] = int.Parse(Console.ReadLine());
}
Buffer.BlockCopy(array1,0,array3,0,array1.Length * sizeof(int));
Buffer.BlockCopy(array2,0,array3,array1.Length * sizeof(int),array2.Length * sizeof(int));
Console.WriteLine("Elements in the Third Array After Appending First and Second Arrays :");
foreach (int value in array3)
{
Console.WriteLine(value);
}
Console.ReadLine();
}
}
Enter Any 5 Elements for the First Array :
1
2
3
4
5
Enter Any 5 Elements for the Second Array :
6
7
8
9
10
Elements in the Third Array After Appending First and Second Arrays :
1
2
3
4
5
6
7
8
9
10
مقادیر رو خودش وارد کرده
من میخوام مقادیر رو از کاربر بگیرم
سلام وقتتون بخیر کد این برنامه با زبان c++ رو میشه قرار بدید 🙂
سلام، مرسی، لینک زیر رو ببینید
https://www.tutorialspoint.com/cplusplus-program-to-push-an-array-into-another-array