Docsity

Lab 6: Fundamentals of Programming - Arrays and Array Operations, Assignments of Computer Programming

Toggle sidebar
bg1
Lab 6
Fundamentals of Programming
Lab Journal - Lab # 6
Objective
This is lab will introduce students to arrays, array input/output and array operations.
Task 1 :
Give answers to the following.
1. Declare an array of 5 double and assign them any values.
2. Assign a value of 6.5 to the 3rd element of the array declared above. Remember first index
of array is zero.
3. Display the first value of the array in question 1.
Computer Programming Lab
Page 1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lab 6: Fundamentals of Programming - Arrays and Array Operations and more Assignments Computer Programming in PDF only on Docsity!

Fundamentals of Programming

Lab Journal - Lab # 6

Objective

This is lab will introduce students to arrays, array input/output and array operations.

Task 1 :

Give answers to the following.

1. Declare an array of 5 double and assign them any values.

2. Assign a value of 6.5 to the 3rd^ element of the array declared above. Remember first index

of array is zero.

3. Display the first value of the array in question 1.

Computer Programming Lab

  1. Using a for loop display the values of the array in question 1.
  2. Using a for loop take all the values of the array in question 1 from user and then display them using another for loop.

Computer Programming Lab

  1. constint^ arraySize^ = 10; int s[ arraySize ]; for ( int i = 0; i <arraySize; i++ ) s[ i ] = 2 + 2 * i; for ( int j = 0; j <arraySize; j++ ) cout<< “Value at index “<< j <<“ is “ << s[ j ] <<endl; Output:

Computer Programming Lab

  1. Int^ billy^ []^ = {10,^ 20,^ 30, 40,^ 50}; int n, result=0; for ( n=0 ; n<5 ; n++ ) { result = result + billy[n]; } cout<< result; Q. Write in one line what is happening in above code fragment. Ans. In the beginning, Array is initialized with string constant. So there is not need to limit the size of array. Output: Exercise 1

Computer Programming Lab

Declare an array of 10 integers and get user input to fill the array values. Then, find the minimum values in the arrays.

Exercise 3

Computer Programming Lab

Write a program to input value in an array of type float and size 10. Find out the average of all the values entered. Formula for average = sum of all values / total number of values

Exercise 4

Computer Programming Lab

Write a program to input value in an array of type integer and size 10. Find out the total number of even and odd values entered in the array.

+++++++++++++++++++++++++

Computer Programming Lab