Getting Familiar with Array Structures 1 Adds corresponding

Getting Familiar with Array Structures: 1. Adds corresponding N elements of arrays ar1 and ar2, storing the result in arsum. Declare ar1 and ar2 with the following initializations and make sure to print out the entire contents of each array. 2. Searching an array of integer elements for contents double ar1 = {3.0, 21.0, 0.0, -3.0, 67.0, -11.0, 23.0, 19.0, 8.0, 18.0} double ar2 = {5.0, 20.0, 11.0, -33.0, 29.0, 8.0, 3.0, 44.0} a. Use looping structures to initialize your array with 10 integers. b. Then, modified the integer array to the counting variable plus itself that means array[x] = (x+x) Write a program to prompt a user to enter a numeric search value. After the search process, the program should alert the user if the value was found and at which element number. If no match was found, it should also alert the user.

Solution

1)

N=8; % Length of the arr1 and arr2
arr1=rand(1,N)% Initilization of arr1 with N random numbers
arr2=rand(1,N) %Initilization of arr2 with N random numbers
arsum=arr1+arr2 % Storing sum of arr1 and arr2 into arsum

OUTPUT:

arr1 =
0.4387 0.3816 0.7655 0.7952 0.1869 0.4898 0.4456 0.6463
arr2 =
0.7094 0.7547 0.2760 0.6797 0.6551 0.1626 0.1190 0.4984
arsum =
1.1481 1.1362 1.0415 1.4749 0.8420 0.6524 0.5646 1.1447

(2)

ar1=[3.0, 21.0, 0.0, -3.0, 67.0, -11.0, 23.0, 19.0, 8.0, 18.0];
ar2 = [5.0, 20.0, 11.0, -33.0, 29.0, 8.0, 3.0, 44.0];

for i=1:length(arr1)
ar1(i)=ar1(i)+ar1(i);
end

for i=1:length(arr2)
ar2(i)=ar2(i)+ar2(i);
end

prompt = \'Enter a Number : \';
number= input(prompt);
k=1;
for i=1:length(ar1)
if(number==ar1(i))
k=k+1;
end
end
if(k>1)
fprintf(\'Number was found\ \');
else
error(\'no match was found\');
end

Note: Developed code in MATLAB.

Getting Familiar with Array Structures: 1. Adds corresponding N elements of arrays ar1 and ar2, storing the result in arsum. Declare ar1 and ar2 with the follow

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site