Blogger templates

Some interesting problems [Beginner Level]

Some reading materials

Arrays



Problems

1. First Even number from an array

You will ask the user to enter an array size. Then take that number of inputs from the user in the array. Then find out the first even number and print it after all the inputs have been given.

You've to do it in these two ways.

First Way: You can use two for loops.
Second Way : You can use only one for loop.




2. Last ODD number from an array

You will ask the user to enter an array size. Then take that number of inputs from the user in the array. Then find out the last odd number and print it after all the inputs have been given.

You've to do it in these two ways.

First Way: You can use two for loops.
Second Way : You can use only one for loop.




3. Array Sorting

You will ask the user to enter an array size. Then take that number of inputs from the user in the array. Then you've to sort that array in acceding order.
For example, if the user gives following inputs,

3 5 8 2 12

The output will be like below,

2 3 5 8 12

But, you can only use one array for this. That means  new int[]  will only be found one time in the entire code!




3. Array sorting 2

You will ask the user to enter an array size. Then take that number of inputs from the user in the array. Then you've to sort that array in acceding order.
Then you'll have to print out the number of operation/swapping needed to sort the whole array.
For example, if the user gives following inputs,

3 2 1

The output will be like below,

Total number of operations required : 2

or,

if the user gives following inputs,

1 2 3

The output will be like below,

Total number of operations required : 0

But, you can only use one array for this. That means  new int[]  will only be found one time in the entire code!

No comments

Powered by Blogger.