Professional Documents
Culture Documents
R13 Syllabus
FLOWCHART:
start
Read n
false
Flowchart:
For i=0 in steps of 1 do where i<n
true
Read a[i]
false
false
true
a[i]>max
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
Display a[i]
stop
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*/
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
./a.out
65231
ORIGINAL OUTPUT :
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
4
Enter the elements of the array
1467
Max=7 position=3
Min=1 position=0
7461
--xXx--