C# Sharp Exercises: Multiply corresponding elements of two arrays of integers
C# Sharp Basic: Exercise-31 with Solution
Write a C# program to multiply corresponding elements of two arrays of integers.
Sample Solution:-
C# Sharp Code:
using System;
using System.Collections.Generic;
public class Exercise31 {
public static void Main() {
int[] first_array = {1, 3, -5, 4};
int[] second_array = {1, 4, -5, -2};
Console.WriteLine("\nArray1: [{0}]", string.Join(", ", first_array));
Console.WriteLine("Array2: [{0}]", string.Join(", ", second_array));
Console.WriteLine("\nMultiply corresponding elements of two arrays: ");
for (int i = 0; i < first_array.Length; i++)
{
Console.Write(first_array[i] * second_array[i]+" ");
}
Console.WriteLine("\n");
}
}
Sample Output:
Array1: [1, 3, -5, 4] Array2: [1, 4, -5, -2] Multiply corresponding elements of two arrays: 1 12 25 -8
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# program to convert a hexadecimal number to decimal number.
Next: Write a C# program to create a new string of four copies, taking last four characters from a given string. If the length of the given string is less than 4 return the original one.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework