Take 10 integer inputs from user and store them in an array. Again ask user to give a number. Now, tell user whether that number is present in array or not. ( Iterate over array using while loop ).
i=10a=[]whilei>0puts"Enter number"num=gets.chomp.to_ia.push(num)i=i-1endputs"Enter a number"n=gets.chomp.to_ii=9count=0whilei>=0ifn==a[i]puts"Yes"count=count+1endi=i-1endifcount==0puts"No"end
3.
Take 20 integer inputs from user and print the following: number of positive numbers number of negative numbers number of odd numbers number of even numbers number of 0s.
Write a program to print sum, average of all numbers, smallest and largest element of an array.
10.
Write a program to check if elements of a array are same or not it read from front or back. E.g.-
2
3
15
15
3
2
# You can take any arraya=[1,2,3,3,2,1]i=0mid=a.length/2same=truewhilei<midifa[i]!=a[a.length-i-1]puts"No"same=falsebreakendi=i+1endifsame==trueputs"Yes"end
11.
Make a array by taking 10 input from user. Now delete all repeated elements of the array. E.g.- INPUT : [1,2,3,2,1,3,12,12,32] OUTPUT : [1,2,3,12,32]
Take an array of 10 elements. Split it into middle and store the elements in two dfferent arrays. E.g.- INITIAL array :
58
24
13
15
63
9
8
81
1
78
After spliting :
58
24
13
15
63
9
8
81
1
78
Use slice
13.
Ask user to give integer inputs to make a array. Store only even values given and print the array.
#Hintifnum%2==0a.push(num)end
Level 2
1.
Take a slit of length n where all the numbers are non-negative and unique. Find the element in the array possessing the highest value. Split the element into two parts where first part contains the next highest value in the array and second
part hold the required additive entity to get the highest value. Print the array where the highest value get splitted into those two parts.
Sample input: 4 8 6 3 2
Sample output: 4 6 2 6 3 2