1. |
Write a C program to return the content of the one-dimensional array as
defined below.
int number[10]={36, 81, 45, 17, 69, 3, 23, 92, 70,
54};
Sample Output Array index = 6 Content =
23
Array index = 10 Out of range
Array index = 3 Content = 17
: |
|
|
2. |
Write a C program to search the numbers in the one-dimensional array as
defined below.
int number[10]={36, 81, 45, 17, 69, 3, 23, 92, 70,
54};
Sample Output Number = 70 Index = 8
Number = 45 Index = 2
Number = 89 Not found
: |
|
|
3. |
Write a C program to update an element in the one-dimensional array as
defined below.
int number[10]={36, 81, 45, 17, 69, 3, 23, 92, 70,
54};
Sample Output 36, 81, 45, 17, 69, 3, 23, 92, 70,
54,
Array index = 2 Reset value = 123
36, 81, 123, 17, 69, 3, 23, 92, 70, 54,
Array index = -1 Array index = 8 Reset value =
316
36, 81, 123, 17, 69, 3, 23, 92, 316, 54,
: |
|
|
4. |
Write a C program to swap any two elements in the one-dimensional array
as defined below.
int number[10]={36, 81, 45, 17, 69, 3, 23, 92, 70,
54};
Sample Output 36, 81, 45, 17, 69, 3, 23, 92, 70,
54,
Input two indexes = 0 2
45, 81, 36, 17, 69, 3, 23, 92, 70, 54,
Input two indexes = 3 12 Input two indexes = 3 2
45, 81, 17, 36, 69, 3, 23, 92, 70, 54,
: |
|
|
5. |
Write a C program to input n integers and then return them in reverse
order.
Sample Output number of integers: 6 number 0 =
25 number 1 = 17 number 2 = 23 number 3 =
8 number 4 = 45 number 5 = 66
the numbers in reverse order are 66, 45, 8, 23, 17, 25, |
|
|
6. |
Write a C program to input n integers and then return the odd numbers
and the numbers in the odd entries separately. Sample
Output number of integers: 6 number 0 =
25 number 1 = 17 number 2 = 23 number 3 =
8 number 4 = 45 number 5 = 66 the odd
numbers are 25, 17, 23, 45, the numbers in the odd entries are 17, 8,
66, |
|
|
7. |
Write a C program to generate mark 6 numbers with reference to the
method as shown below.
|
|
|
8. |
The following algorithm arranges the first n integers in a random
order:
1. Store the first n integers in an array number[] so that number[0]
contains 0, number[1] contains 1, etc. 2. Randomly generate two
different integers x and y between 0 and n-1 inclusively. 3.
Interchange the contents of number[x] and number[y]. 4. Repeat step (2)
and (3) for 10*n times. 5. Output the contents of all the array
elements.
Convert the algorithm into a C program. |
|
|
9. |
With reference to question 8, write a C program to generate the
following sample output.
Sample Output A random number is drawn from 0 to 51
17, x, x, x, x, x, x, x, x Will the next drawn number be bigger (1)
than or smaller (0) than this one? 1 You are right
17, 43, x, x, x, x, x, x, x Will the next drawn number be bigger (1)
than or smaller (0) than this one? 0 You are right
17, 43, 29, x, x, x, x, x, x Will the next drawn number be bigger
(1) than or smaller (0) than this one? 0 You are wrong
17, 43, 29, 36, x, x, x, x, x You lose the game
: |
|
|
10. |
Write a C program to insert an element in the one-dimensional array as
defined below.
int number[100]={36, 81, 45, 17};
Sample Output
36,
81, 45, 17
Array index = 2
New element = 23
36, 81, 23, 45, 17,
Array index = -1
Array index = 5
New element = 2
36, 81, 23, 45, 17, 2,
: |
|
|
11. |
Write a C program to delete an element from the one-dimensional array
as defined below.
int number[10]={36, 81, 45, 17, 69, 3, 23, 92, 70,
54};
Sample Output
36, 81, 45, 17, 69, 3, 23, 92, 70,
54,
Array index = 1
36, 45, 17, 69, 3, 23, 92, 70, 54,
Array index = -1
Array index = 8
36, 45, 17, 69, 3, 23, 92, 70,
:
|
|
|
12. |
<<< Mastermind >>>
Number of colors available: Red (1), Orange (2), Yellow (3), Green (4),
Blue (5), Brown (6) Colors may be repeated but null value is not
allowed. You can guess at most 6 times.
answer |
guess |
|
|
|
|
answer_matched |
guess_matched |
|
|
Sample Output
Trial 1 : 1 2 3 2 1 Black, 1
White
Trial 2 : 3 4 5 6 1 Black, 0 White
Trial 3 : 2 3 6 1 0 Black, 3 White
Trial 4 : 1 6 2 6 4 Black, 0 White
The answer is 1 6 2 6
Congratulation! You win the game. |
|
|
|
|
|
|
|
|
|
|