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

0, Min A (0) : Raghu Institute of Technology

The document contains a C program to interchange the largest and smallest numbers in an array. It includes: 1) The algorithm which takes input of array size n, finds maximum and minimum elements and their positions, swaps maximum and minimum elements, and displays final array. 2) Flowchart showing the steps of finding maximum and minimum elements, swapping them, and displaying output. 3) The C program code implementing the algorithm along with sample input/output.

Uploaded by

prasad9440024661
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)
122 views

0, Min A (0) : Raghu Institute of Technology

The document contains a C program to interchange the largest and smallest numbers in an array. It includes: 1) The algorithm which takes input of array size n, finds maximum and minimum elements and their positions, swaps maximum and minimum elements, and displays final array. 2) Flowchart showing the steps of finding maximum and minimum elements, swapping them, and displaying output. 3) The C program code implementing the algorithm along with sample input/output.

Uploaded by

prasad9440024661
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/ 7

RAGHU INSTITUTE OF TECHNOLOGY

RAGHU INSTITUTE OF TECHNOLOGY


DEPARTMENT OF CSE
College Code: 3J

R13 Syllabus

C PROGRAMMING LAB MANUAL


====================================================================
Exercise 5
a) Write a C program to interchange the largest and smallest numbers in the array.
b) Write a C program to implement a liner search.
c) Write a C program to implement binary search.
====================================================================
SPECIFICATION:
(5)(a).C Program to interchange the largest and smallest element in an array
ALGORITHM:
Step 1: Start
Step 2: Declare intger variables n ,i ,minp ,maxp ,max=0,min=0,temp
Step3: Initialize max0, min a[0]
Step 4:Read n
Step 5: i is initilised as 0 and in steps of 1 do the condition i<n is checked until it fails
Step 5.1: read a[i]
Step 6: i is initilised as 0 and in steps of 1 do the condition i<n is checked until it fails
Step 6.1: check a[i]>max then
Step 6.1.1: max  a[i]
Step 6.1.2: max  i
Step 7: Display max , maxp
Step 8 : i is initilised as 0 and in steps of 1 do the condition i<n is checked until it fails
Step 8.1: check a[i]<min
Step 8.1.1 : min a[i]
Step 8.1.2: minpi
Department of Computer Science & Engg

RAGHU INSTITUTE OF TECHNOLOGY

Step 9: Display min , minp


Step 10: temp max
Step 11: a[maxp]a[minp]
Step 12: a[minp] temp
Step 13: for i=0 in steps of 1 do where i<n
Steps 13.1Display a[i]
Step 14: Stop

Department of Computer Science & Engg

RAGHU INSTITUTE OF TECHNOLOGY

FLOWCHART:
start

declare intger variables n ,i ,minp,maxp,a[50]


initialize max=0,min=a[0]

Read n
false
Flowchart:
For i=0 in steps of 1 do where i<n
true
Read a[i]

For i=0 in steps of 1 do where


i<n

false
false

true
a[i]>max

For i=0 in steps of 1 do where


i<n

true

false

true
Max a[i]
a[i]<
min

Maxp  i
true

min=a[i]
minp=i

temp  max
a[maxp] a[minp]
false
a[minp]temp

For i=0 in steps of 1 do where i<n


true
Department of Computer Science & Engg

Display a[i]

stop

RAGHU INSTITUTE OF TECHNOLOGY

PROGRAM
/*C Program to interchange the largest and smallest numbers in the array. */
Program name:
/* Done By : C-Faculty
#include<stdio.h>
#include<curses.h>
int main()
{
int n,i,minp,maxp,max=0,min=0,temp;
clear();
printf(enter the value of n\n);
scanf(%d,&n);
printf(enter the elements);
for(i=0;i<n;i++)
{
scanf(%d,&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
maxp=i;
}
}
Department of Computer Science & Engg

// wk1a.c
Dated: 15/10/2013*/

RAGHU INSTITUTE OF TECHNOLOGY

printf(max=%d position=%d,max,maxp);
for(i=0;i<n;i++)
{
if(a[i]<a[i+1])
{
min=a[i];
minp=i;
}
}
printf(min=%d position=%d,min,minp);
temp=max;
a[maxp]=a[minp];
a[minp]=temp;
for(i=0;i<n;i++)
{
printf(%d,a[i]);
}
return(0);
}
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk5a.c lcurses -lm
Step 3: Now go for running the program by using the command

Department of Computer Science & Engg

RAGHU INSTITUTE OF TECHNOLOGY

./a.out

Step 4: To create an executing file use the command


cc wk5a.c -curses o lasmaarray

EXPECTED I/P AND O/P:


Output (1)
enter the value of n
5
Enter the array elements
23579
Max=9 position=4
Min=2 position=0
93572
Output (2)
enter the value of n
6
Enter the elements of the array
15236
Max=6 position=5
Min=1 position=0

65231

ORIGINAL OUTPUT :
Output (1)
enter the value of n
5
Enter the array elements

Department of Computer Science & Engg

RAGHU INSTITUTE OF TECHNOLOGY

23579
Max=9 position=4
Min=2 position=0
93572
Output (2)
enter the value of n
4
Enter the elements of the array
1467
Max=7 position=3
Min=1 position=0

7461

--xXx--

Department of Computer Science & Engg

You might also like