Fundamentals of Programming Lab Journal - Lab # 6: Objective
Fundamentals of Programming Lab Journal - Lab # 6: Objective
Fundamentals of Programming Lab Journal - Lab # 6: Objective
Fundamentals of Programming
Enrollment #: 01-235181-029
Class: BS(IT)-1A
Objective
Introduction to 1D arrays.
Array input/output and array operations.
2D arrays
Sorting
Task 1 :
Give answers to the following. Write only the coding statement which is asked not the whole
program.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
double arr[] = { 1.2, 3.4, 6.2, 1.9, 7.8 };
_getch();
return 0;
}
2. Assign a value of 6.5 to the 3rd element of the array declared above. Remember first index of array is zero.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
double arr[] = { 1.2, 3.4, 6.5, 1.9, 7.8 };
_getch();
return 0;
}
5. Using a for loop take all the values of the array in question 1 from user and then display them using another
for loop.
Task 2 :
1.
int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
Output:
int s[ arraySize ];
s[ i ] = 2 + 2 * i;
Output:
int n, result=0;
Output:
Exercise 1
Declare an array of 10 integers and get user input to fill the array values. Then, find
the minimum values in the arrays.
Exercise 2
Write a program where you declare 3 arrays of 5 integers each. For two of the
arrays get the values from the user. Add the respective elements of these two
arrays and store the results in the third array.
Example:
Array1= 1 2 3 4 5
Array2 = 1 1 2 2 4
Ar
Computer Programming Lab
Page 8
Lab 6
Exercise 3
OUTPUT :
Exercise 4
Write a program to input value in an array of type integer and size 10. Find out the
Computer Programming Lab
total number of even and odd values entered in the array.
Page 9
Lab 6
Exercise 5
Write a program to input value in an array of type float and size 10. Find out the
average of all the values entered.
OUTPUT :
Exercise 6
Write a C++ program that declares a 1D array of size 20 and assign values to it.
Apply Bubble sorting on this array and sort it in ascending order.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a[20];
for (int i = 0; i < 20; i++)
{
cout << "Enter the value in index " << i << " =";
cin >> a[i];
}
cout << endl;
cout << "Values in Array before sorting (Acending)" << endl;
for (int j = 0; j < 20; j++)
{
cout << "value in index " << j << " is =" << a[j] << endl;
}
int dell;
for (int k = 0; k < 19; k++)
{
for (int l = 0; l < 19; l++)
{
if (a[l] > a[l + 1])
{
dell = a[l];
a[l] = a[l + 1];
a[l + 1] = dell;
}
}
}
cout << endl;
cout << "Values in Array After sorting (Acending)" << endl;
for (int m = 0; m < 20; m++)
{
cout << "Value in index " << m << " is " << a[m] << endl;
}
_getch();
return 0;
}
Home Task
Write a C++ program that declares an array of size 20 and assign values to it. Then
it asks the user “Enter the number to search in this array”. Then search the number
entered by user in the array and display the index on which it was found. (This task
is similar to exercise 1. Think like that.)
+++++++++++++++++++++++++