0% found this document useful (0 votes)
26 views

Array Part 1 Name: - Student Id: - Group

The document contains questions about arrays in C programming. It asks the student to: 1) Define an array of prime numbers and describe how its contents change after two for loops. 2) Find the output of printf statements accessing elements of a given array. 3) Calculate the total after four for loops operating on elements of an array. 4) Write a program to display user ratings in a graph. 5) Write a loop to count elements equal to 1 in an array. 6) Write a program to copy one array into another. 7) Draw tables for two given multi-dimensional arrays. 8) Write a program using a 2D array and for loops to produce a specified output

Uploaded by

LUQMAN MEN
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Array Part 1 Name: - Student Id: - Group

The document contains questions about arrays in C programming. It asks the student to: 1) Define an array of prime numbers and describe how its contents change after two for loops. 2) Find the output of printf statements accessing elements of a given array. 3) Calculate the total after four for loops operating on elements of an array. 4) Write a program to display user ratings in a graph. 5) Write a loop to count elements equal to 1 in an array. 6) Write a program to copy one array into another. 7) Draw tables for two given multi-dimensional arrays. 8) Write a program using a 2D array and for loops to produce a specified output

Uploaded by

LUQMAN MEN
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Array Part 1

Name: ______________________________________student id: _______________________ Group:___________

1. Answer the following questions.


a) Define an array of integers containing the first five prime numbers.
b) What is the content of array in (a) after executing the following loop?
for (i = 0; i < 2; i++)
{
prime[4 – i] = prime[i];
}
c) What is the content of array in (b) after executing the following loop?
for (i = 0; i < 5; i++)
{
++prime[i];
}
2. Given the following array. Find the output for each below:
array [ ]= { 12.2, 2.0., 1.54, -52, 9.2, 86};
n = 2;
a) printf(“%d”,array[4] );
b) printf(“%d”,array[n] +1 );
c) printf(“%d”,array[n + 1] );
d) printf(“%d”,array[2 * n - 3] );

3. What is the value of total after the following loops complete?


a [ ] = { 1, 2, 3 , 4, 3, 2 ,1 , 0};
a) for (i = 1; i < 7; i += 2) { total += a [i]; }
b) for (i = 2; i <= 6; i ++) { total += a [i]; }
c) for (i = 7; i >= 0; i -= 2) { total += a [i]; }
d) for (i = 3; i < 7; i *= 2) { total += a [i]; }

4. Write a program that read ratings from 10 users and display the ratings in a graph as shown below.
**The sample output as shown below.
Insert your rate (1 - 5)>> 2
Insert your rate (1 - 5)>> 4
Insert your rate (1 - 5)>> 2
Insert your rate (1 - 5)>> 1
Insert your rate (1 - 5)>> 1
Insert your rate (1 - 5)>> 3
Insert your rate (1 - 5)>> 1
Insert your rate (1 - 5)>> 1
Insert your rate (1 - 5)>> 2
Insert your rate (1 - 5)>> 5

Rating Graph
--------------------------
1: ****
2: ***
3: *
4: *
5: *
5. Write a loop that counts how many elements in array below are equal to one.
counting [ ] = {2, 4, 4, 1, 0, 9, 1};
6. Write a program that copy the array below into array called copied.
original [ ] = { ‘P’, ‘E’, ‘Y’, ‘R’};
7. Draw the table for the following array.
a) int cube [ 2 ] [ 4 ] = {4, 8, 12, 16, 20, 24, 28, 32};
b) int exam [ 3 ] [ 3 ] = {{45, 56, 78}, {69, 48}, {94}};

8. By using two-dimensional array and for loop, write a program that will produce below output.
Hint: use formula to check even number.

1212
2121
1212
2121

You might also like