Math, asked by rakibsuvro19, 9 months ago

Suppose you are going to take a class test for 12 students of a course. So that, you need to write a program for taking input as marks obtained by each student from the keyboard in order to store into an array named CT1. Also, your written program able to calculate and print the average marks of this course obtained by students.

please c program solve now?

Answers

Answered by abcdefghi76
0

Answer:

ObjectivesDeclare, Initialize, and Use ArraysUse Loops for Array TraversalPass Arrays as ParametersReturn Arrays from MethodsUnderstand Reference Semantics(Optional) Use Arrays to Store and Process Data from Files(Optional) Use Multidimensional ArraysAssignmentsComplete zyBook Chapters 13 and 14 participation and challenge activities before each class and before the Wednesday deadline of respective week

Chapter 13 zyLab activities due beginning of Week 14 and Chapter 14  zyLab activities due beginning of Week 15

Finish Project 3 (Due begining of Week 16)Array BasicsConsider the following interaction (input in red): 

How many days' temperatures? 7 Day 1's high temp: 45 Day 2's high temp: 44 Day 3's high temp: 39 Day 4's high temp: 48 Day 5's high temp: 37 Day 6's high temp: 46 Day 7's high temp: 53 Average temp = 44.6 4 days were above average.

We need to be able to read each input value twice: once to compute the average (a cumulative sum) and again to count how many were above average.  We could read each value into a variable, but we don't know how many days are needed until the program runs, so we don't know how many variables to declare. 

We need a way to declare many variables in one step and then be able to store and access their values. 

Challenge: Is it possible to solve the above problem using only the techniques from the previous notes without using arrays? How?

ArraysAn array is an object that stores many values of the same type.  An array element is one value in an array.  An array index is an integer indicating a position in an array.  Like Strings, arrays use zero-based indexing, that is, array indexes start with 0.  The following displays the indexes and values in an array with 10 elements of type int. 

index    0    1    2    3    4    5    6    7    8    9  value   12 49 -2 26  5 17 -6 84 72  3

Array declaration and creationThe syntax for declaring an array is:

type[ ] variable;

This just declares a variable that can hold an array, but does not create the array itself.

For example, to declare a variable, numbersthat can hold an array of integers, we would use:

int[] numbers;

Since arrays are objects, we create arrays using new. 

When creating an array, you specify the number of elements in the array as follows:

variable = new type[length];

For example, to create an array of 10 integers:

numbers = new int[10];

We can combine the two operations of declaring and creating an array:

type[ ] variable = new type[length];

Our example would become:

int[ ] numbers = new int[10];  // an array of 10 ints

This would assign the following array to the variable numbers. 

index    0    1    2    3    4    5    6    7    8    9  value    0  0  0  0  0  0  0  0  0  0

Each element in an array is initialized to zero, or whatever is considered "equivalent" to zero for the data type (false for booleans and nullfor Strings). 

Storing Values and Accessing ElementsThe syntax for storing a value in an array element is: 

variable[index] = expression;

For example: 

numbers[0] = 27; numbers[3] = -6;

would change the numbers array to: 

index    0    1    2    3    4    5    6    7    8    9  value   27  0  0 -6  0  0  0  0  0  0

The syntax for accessing an array element is: 

variable[index]

where the index can be any expression that results in an int. For example: 

System.out.println(numbers[0]); if (numbers[3] > 0) { System.out.println(numbers[3] + " is positive"); } else { System.out.println(numbers[3] + " is not positive"); }

When you declare an array, each element of the array is set to a default initial value.

For integers, the default value is 0. What do you think the default value is for doubles? 

Activity: Array default initial values

Write a program that declares a double array of length 4, prints the values, assigns a value to each element, and prints the values again.

Now do the same thing for an array of Stringelements.

Arrays and LoopsWe can use an integer variable as the index of an array.  If we use a for loop to count from 0 to the highest index, then we can process each element of an array.  For example, the following code would sum the elements in the numbers array. 

int sum = 0; for (int i = 0; i < 10; i++) { sum += numbers[i]; }

We start at 0 because indexes start at 0.  We end just before 10 because 10 is the length of our numbers array, and the last index is one less than the length of the array.

[Arrays provide many opportunities for off-by-one errors because of the way indexes work.] 

If we changed the numbers array to have a different number of elements, this code would no longer work.  Fortunately, Java provides a easy way to obtain the length of an array, by appending .length after the array variable, for example: 

int sum = 0; for (int i = 0; i < numbers.length; i++) { sum += numbers[i]; }

Notice that for arrays we do not use parentheses after the length.

This is different from the way the length is done for strings. 

hi hope...........

Similar questions