0% found this document useful (0 votes)
19 views

C Arrays

The document provides instructions for two C programming exercises using arrays: 1) Write a program to find the maximum and minimum numbers in an array. It should initialize variables, take array size and elements as input, set initial min and max, compare each element to min and max, and print the results. 2) Write a program to separate even and odd numbers in an array. It should initialize variables, take array size and elements as input, use two for loops to check the remainder of each element when divided by 2 to identify even and odd numbers.

Uploaded by

soethurein227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

C Arrays

The document provides instructions for two C programming exercises using arrays: 1) Write a program to find the maximum and minimum numbers in an array. It should initialize variables, take array size and elements as input, set initial min and max, compare each element to min and max, and print the results. 2) Write a program to separate even and odd numbers in an array. It should initialize variables, take array size and elements as input, use two for loops to check the remainder of each element when divided by 2 to identify even and odd numbers.

Uploaded by

soethurein227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MANDALAY TECHNOLOGICAL UNIVERSITY

DEPARTMENT OF ELECTRONIC ENGINEERING

EXPERIMENT (1)
LABORATORY REPORT

FOR
SECOND YEAR EcE-22014
(SECOND SEMESTER)

Technical Programming II
Lab 1: C Arrays

Name ……………………………………………….…………………………
Roll no. ………………………………………………..….…………………...
Mandalay Technological University
Electronic Engineering Department
EcE-22014 Technical Programming
EXPERIMENT 1
CHAPTER 6, C ARRAYS

Course Outcomes

After the completion of this chapter, the students will be able to

✓ use the array data structure to represent lists and tables of values
✓ define an array, initialize an array and refer to individual elements of an array
✓ pass arrays to functions
✓ use arrays to store, sort and search lists and tables of values

Exercise 1

To find the maximum and minimum of given numbers in array.

How do you think to write a program?

First Step: This program starts with initializing:


✓ i→Helping Variable
✓ size→Indicates size of array i.e, number of elements to be sorted in array
✓ max,min→To store maximum and minimum numbers from given array
✓ a[size]→To store array elements of given size

Second Step: Taking size and array elements as input from user
✓ Enter size and print it
✓ Enter numbers in array to find max and min and print them by using for loop

Third Step: Initializing min, max to first element in array


✓ min=a[0];
✓ max=a[0];
✓ So lets take array elements say, 45, 30, 35, 32, then min=45 and max=45

Fourth Step: a[i] is compared by max and min.


✓ If it is greater than max, the value of max is replaced by the value of a[i].
✓ If it is less than min, the value of min is replaced by the valu of a[i].
✓ Iterate from 1st element till the last element in array by using for loop.

Fifth Step: Finally min and max will be printed.


Exercise

To separate even and odd numbers in array.

How do you think to write a program?

First Step: the program starts with initializing


✓ size→To store size of array
✓ i→Temporary variable
✓ a→To store array elements

Second Step: Taking size and array elements as input from user
✓ Enter size and print it
✓ Enter numbers in array to separate even and odd and print them by using for loop

Third Step: Calculating the even numbers in array


✓ For even number→if a[i]>=0i.e whether the number at position, i is greater than zero or
not just to avoid 0’s to print. If the value of a[i] is divided by 2 and then the remainder is
equal to 0 zero, the value of a[i] is even. If it is even or not, using a[i]%2==0 which is used
to identify even numbers. This is the 1st for loop.
✓ Iterate from 1st element of array till the last element in array by using for loop

Fourth Step: Calculating the odd numbers in array


✓ For odd number→a[i]>=0 and it continued to check. If the value of a[i] is divided by 2 and
then the remainder is not equal to 0 zero; otherwise the remainder is equal to 1, the value
of a[i] is odd. This is the 2nd for loop.
✓ Iterate from 1st element of array till the last element in array by using for loop.

You might also like