Professional Documents
Culture Documents
7 Marks 8 Marks
Objectives
The main objective of this lab is to understand the concept of Arrays.
Lab Instructions
The students should perform and demonstrate each lab task separately for step-wise
evaluation
Each group shall submit one lab report on LMS within 6 days after lab is conducted. Lab
report submitted via email will not be graded.
Students are however encouraged to practice on their own in spare time for enhancing their
skills.
Complete as many problems as you can within the allotted time.
Talk to your classmates for help
Lab Report Instructions
All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:
Lab objectives
C codes with proper indentation
Above each line of Code, use two slashes // to write a comment to yourself
explaining what the line does.
Results (screen shots) duly commented and discussed
Conclusion
TASK 1
CODE:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int array_1[5], array_2[5], i, j, Size; //declaring two arrays and size of array
printf("Enter the size of an array: "); //prompt for entering the size of array
for (i = 0; i < Size; i++) //for loop for the size of element
for (i = Size - 1, j = 0; i >= 0; i--, j++) //for loop for reversing the elements stored un array
printf("Result of an reverse array is:"); //prompt for printing the reversal of array
for (i = 0; i < Size; i++) //for loop for reversing the elements of array
COMMENTS:
In this lab task we asked the user to enter the size of array, then asked the user to enter the
elements and printed the elements in reversal order.
TASK 2
CODE:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int Array[9], i, j, temp, Size; //declaring the array and size of array and a variable tamp
printf("Enter the number of elements in an array:"); //prompt for entering the elements
for (i = 0; i < Size; i++) //for loop for array one elements
for (j = i + 1; j < Size; j++) //for loop for array two elements
if (Array[i] < Array[j]) //condition if element of array one is less than element of array two
Array[i] = Array[j]; //storing the value of element of array two in array one
COMMENTS:
In this lab task we simply asked the user to enter the size of array , then the asked the user the enter
the elements of that array and then using the for loop we simply printed the elements in descending
order.
TASK 3
CODE:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
{
int i, array[9], size, sum = 0; //declaring the array , sum and size of elements
printf("Enter number of Array Elements:"); //prompt for entering the size of array
sum_of_Even(a, num - 1, sum); //again calling the sum_of_Even elements function for else condition
printf("The sum of even numbers of array = %d\n", sum); //printing the even elements
}
COMMENTS:
In this lab task we asked the user to enter the size of array and the elements of array as well, the
with the help of functions and array and if statements we simply printed the sum of even elements
of array.
CONCLUSION:
In the performing the all lab tasks we simply learned the use of arrays , how to declare array and
how to store the value in an array and then print it . We also learned how to find the sum of even
number of array and how to print array in we reversal order and how to print the elements of array
in descending order.