Write a program that asks the user to enter up to 20 integers.Store the integers in an array of longs. Then, the program should ask the user to enter an integer. The program should use the function Find_It()to locate the integer in the array. The third argument in Find_It() is the address of the found integer. The function should return 1 if the integer is found and 0 otherwise. If the integer is found, the program should replace the integer by its negative and display the elements in the array. If the integer is not found, display an appropriate message.
1
Expert's answer
2016-03-31T11:00:41-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace array { class Program { static void Main(string[] args) { long[] array = new long[20]; for (int i = 0; i < 20; i++) { Console.WriteLine("Enter " + (i+1) + " number of array"); array[i] = Convert.ToInt64(Console.ReadLine()); } Console.WriteLine("Enter number that you want to find"); int numb = Convert.ToInt32(Console.ReadLine()); int result = 0; if (Find_It(array, numb, ref result) == 0) { Console.WriteLine("There is not this number in array"); } else { array[result] *= -1; foreach (long n in array) { Console.WriteLine(n); } } Console.Read(); }
public static int Find_It(long[] mas, int a, ref int res) {
for (int i = 0; i < mas.Length; i++) { if (a == mas[i]) { res = i; return 1; } } return 0; } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment