Chandan Sharma

Chandan Sharma

  • NA
  • 12
  • 3.5k

Program for shorting is not working

Nov 29 2018 9:12 AM
#include<stdio.h>
#include<conio.h>
void main()
{
int arr1[5]={2,1,4,3,5},arr2[5]={6,7,9,5,8},arr3[10],i,j,temp,k=0;
clrscr();
for(i=0;i<10;i++)
{
if(i>4)
{
arr3[i]=arr2[k];
k++;
}
else
arr3[i]=arr1[i];
}
printf("elements are \n ");
for(i=0;i<10;i++)
{
printf("\n %d",arr3[i]);
}
for(i=0;i<9;i++)
{
for(j=j+1;j<10;j++)
{
if(arr3[j] >arr3[i])
{
temp=arr3[i];
arr3[i]=arr3[j];
arr3[j]=temp;
}
}
printf("\n shorted elements are \n");
for(i=0;i<10;i++)
{
printf("\t %d",arr3[i]);
}
getch();
}
}

Answers (1)