Output:
Enter element
1
2
3
4
5
After exchanging
5
2
3
4
1
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,n,max,min,maxl=0,minl=0;
clrscr();
printf("Enter array size");
scanf("%d",&n);
printf("Enter any %d Elements \n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
min=a[0];
max=a[0];
}
for(i=0;i<n;i++)
{
if(a[i]<min)
{
min=a[i];
minl=i;
}
if(a[i]>max)
{
max=a[i];
maxl=i;
}
}
printf("Minimum is %d \n Maximum is %d ",min,max);
a[minl]=max;
a[maxl]=min;
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}
Enter element
1
2
3
4
5
After exchanging
5
2
3
4
1
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,n,max,min,maxl=0,minl=0;
clrscr();
printf("Enter array size");
scanf("%d",&n);
printf("Enter any %d Elements \n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
min=a[0];
max=a[0];
}
for(i=0;i<n;i++)
{
if(a[i]<min)
{
min=a[i];
minl=i;
}
if(a[i]>max)
{
max=a[i];
maxl=i;
}
}
printf("Minimum is %d \n Maximum is %d ",min,max);
a[minl]=max;
a[maxl]=min;
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}
No comments:
Post a Comment