You are on page 1of 8

Department of Electrical Engineering

Faculty Member: taha ali_____________ Dated: _____16/02/22_______________

Course/Section: BEE 13 -D Semester: Fall 2021

CS-114 Fundamentals of Programming

Lab11: Introduction to Arrays

Name Reg. No Viva / Analysis


Quiz / Lab of data
Performa in Lab
nce Report

7 Marks 8 Marks

AWAIS AHMED 384685


Lab11: Introduction to Arrays

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 main(void) //main function

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

scanf("%d", &Size); //taking size as input from user

printf("Enter array elements: ");

for (i = 0; i < Size; i++) //for loop for the size of element

scanf("%d", &array_1[i]); //taking the elements of array as input from user

for (i = Size - 1, j = 0; i >= 0; i--, j++) //for loop for reversing the elements stored un array

array_2[j] = array_1[I]; //assigning the value of array_1 In array_2

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

printf(" %d ", array_2[i]); //printing the elements of array in reversal order

printf("\n"); //escape sequence

return 0; //return type is integer


}

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 main(void) //main function

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

scanf("%d", &Size); //taking the size of elements as input

printf("Enter %d elements of an Array:", Size); //printing the size of array

for (i = 0; i < Size; i++) //for loop for size of elements

scanf("%d", &Array[i]); //taking the elements of array as input from user

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

temp = Array[i]; //storing the value of array one in temp variable

Array[i] = Array[j]; //storing the value of element of array two in array one

Array[j] = temp; //storing the value of temp in array two

printf("Elements of Array in Descending Order are:"); //prompt for descending order

for (i = 0; i < Size; i++) //for loop for descending order

printf(" %d ", Array[i]); //printing the elements in descending order

printf("\n"); //escape sequence

return 0; //returning an value of integer type


}

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>

void sum_of_Even(int a[], int num, int sum); //function prototyoe

int main(void) //main function

{
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

scanf("%d", &size); //taking the size as input from user

printf("Enter Array Elements:"); //prompt for entering the elements

for (i = 0; i<size; i++) //for loop for elements of array

scanf("%d", &array[i]); //taking the elements as input from user

sum_of_Even(array, size- 1, sum); //calling the sum_of_elements function from main

void sum_of_Even(int a[], int num, int sum) //function definition

if (num >= 0) //condition for if element is greater then 0

if ((a[num]) % 2 == 0) //condition if element of gives 0 in division

sum += (a[num]); //then the sum of even elements will be printed

sum_of_Even(a, num - 1, sum); //again calling the sum_of_Even elements function for else condition

else //else condition

printf("The sum of even numbers of array = %d\n", sum); //printing the even elements

return; //returning the integer type

}
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.

You might also like