Playing With Arrays
The following problems are to give you practice with programming with arrays. Write a program to:
1.Ask the user for numbers and place them in an array sequencially.
2.Next, print out the values in the array in the order they are stored.
3.Search the array for the postion containing the smallest value.
4.Print out the position where the smallest value was found.
5.Swap the smallest value with the value in the first postition of the array.
6.Print out the array in the order they are now stored.
7.Reverse the elements of the array.
8.Print out the array in the order they are now stored.
9.Add 1 to every odd number in the array.
10.Print out the array in the order they are now stored.
11.Repeatedly ask the user for a number and printout the
position in the array where that number is stored. Print
"Not Found" if the number is not in the
array.
Quit when the user enters a sentinel value (such as -1).
Directions
You must write a method to print out the elements of the array in the order they are stored. Use that method every time the array is printed.
Test your program thoroughly. Include a screen-grab printout of your tests and the results.
Hints:
Build up the program incrementally. Just do step 1 above and test it. Once working, add in step 2. Then test it. Then step 3, and so on.
Thanks for the help
NOTE: I have completed code according to your requirement and assuming the language is Java. If not, please let me know the language required i will code accordingly. Please check and let me know if you have any questions. I will acknowledge back within 24 hours. Thanks for your patience.
Code:
import java.util.Scanner;
class Main{
public static void main(String[] args){
// declaring variables
Scanner sc = new Scanner(System.in);
int n, min_pos = 0, min;
int[] arr = new int[100];
int[] temp_arr = new int[100];
// checking how many numbers user want to enter
System.out.println("Enter how many values? ");
n = sc.nextInt();
// getting the set of numbers user want to enter
for(int i = 0; i < n; i++){
System.out.println("Enter "+(i+1)+ " number: ");
arr[i] = sc.nextInt();
}
System.out.println("Given array elements are:");
//printing the numbers stored in array
for(int i = 0; i < n; i++)
System.out.println(arr[i]+ " ");
// searching array for smallest number position
min = arr[0];
for(int i = 1; i < n; i++)
if(arr[i] < min){
min_pos = i;
min = arr[i];
}
// printing the smallest number position
System.out.println("Smallest number is at position: "+
min_pos);
// swap smallest value with value in first position of the
array
int t = arr[0];
arr[0] = arr[min_pos];
arr[min_pos] = t;
// printing the numbers in arrays again
System.out.println("Array elements after swapping with min value
position is:");
for(int i = 0; i < n; i++)
System.out.println(arr[i]+ " ");
// reversing numbers in array
int k = 0;
for(int j = n-1; j >= 0; j--)
temp_arr[k++] = arr[j];
for(int i = 0; i < n; i++)
arr[i] = temp_arr[i];
// printing the array in the order now it is stored
System.out.println("Array elements after reversing:");
for(int i = 0; i < n; i++)
System.out.println(arr[i]+ " ");
// add 1 to every odd number in the array
for(int i = 0; i < n; i++)
if(arr[i] % 2 == 1)
arr[i] += 1;
// printing the array in the order it is stored now
System.out.println("Array elements after adding 1 to odd
numbers:");
for(int i = 0; i < n; i++)
System.out.println(arr[i]+ " ");
int x;
while(true){
System.out.println("Enter a number to check in array: ");
x = sc.nextInt();
if(x == -1) break;
int i = 0;
for(; i < n; i++)
if(arr[i] == x){
System.out.println("Given number found and it is position "+
i);
break;
}
if(i == n)
System.out.println("Not Found. Try again");
}
}
}
Code output screenshot:


Playing With Arrays The following problems are to give you practice with programming with arrays. Write...
Using Java
In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...
In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...
Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays, and a random number generator. Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Smallest Quit H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user...
(C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...
Q1. Write a program in Java a. Create 2 separate arrays, of user defined values, of same size b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....
Write a program that lets the user enter 10 values into an array. The program should then display the largest and the smallest values stored in the array. The program should display the following message to the user at the beginning "This program will ask you to enter ten values. Then it will determine the largest and smallest of the values you entered.Please enter 10 integers separated by spaces: " And then after user entered the numbers, it should display...
Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps. This is a basic course and the furthest we have gone is BASIC arrays. Write the code for the following problems using arrays. Write what would go in the “int main()” part of the program. For these problems, the entire program and program output is not needed. Just include what goes in the int main() part of the program. 1. Declare an integer array...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...