Exp 8
Exp 8
Experiment No. –8
Date of Performance:
Date of Submission:
Program Execution/
formation/ Timely
Viva Experiment Sign with
correction/ Submission
(03) Total (10) Date
ethical practices (01)
(06)
Experiment No. 8
Study of one-dimensional Array.
Problem Statement: Write a program to find largest and second largest element
of array.
Problem Definition:
Input: Accept elements of an array.
Processing: Sort elements of an array in ascending order.
Output: Display largest and second largest element of sorted array
DeclarationofanArray:
Datatypevariable
name[lengthofarray];forexample,
double
height[10];float
width[20];intmin
[9];
charname[20];
InitializingArrays
Initializing of array is very simple in c programming. The initializing
valuesare enclosed within the curly braces in the declaration and placed following an
equalsignafterthearrayname.Hereisanexamplewhichdeclaresandinitializesanarrayoffi
veelements oftypeint. Arraycanalso beinitialized afterdeclaration.
int myArray[5] = {1, 2, 3, 4, 5}; //declare and initialize the array in one
statementintstudentAge[4];
studentAge[0]=1
4;studentAge[1]
=13;studentAge[
2]=15;studentAg
e[3]=16;
Algorithm:
Step 1:Start
Step2:Declarevariablesand array(i,j,n,x[20],temp)
Step 3:Readthevalueoftotal no.ofelements i.e.ninarray
Step4:Initializei=0,repeatstepno.5untili<totalno.ofelements
Step5:Readtheelementsofarray.
Step6:Initializei=0,Repeatthestepno.7untili<n-1Step7:
Initializej=0,Repeatthestepno.8,9,10untilj<n-1Step
8:temp=x[j]
Step 9:x[j]=x[j+1]
Step 10:x[j+1]=temp
Step 11:Displaythelargestandsecond largestelement
Step 12:Stop
Flow chart
1.6 Conclusion:
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
………………………………
1.7 Questions:
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
…………