please find Error in this code-/* (Descending) Ritu
C program to sort the array in the Descending order */
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array: ");
scanf("%d",&n);
printf("Enter the elements in the array: ");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\n%d",ar[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]<ar[j+1])
{
tmp=ar[j+1];
ar[j+1]=ar[j];
ar[j]=tmp;
}
}
}
printf("\n Array in the Descending order is -\n");
for(i=1;i<=n;i++)
{
printf("\n%d",ar[i]);
}
getch();
}
C program to sort the array in the Descending order */
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array: ");
scanf("%d",&n);
printf("Enter the elements in the array: ");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\n%d",ar[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]<ar[j+1])
{
tmp=ar[j+1];
ar[j+1]=ar[j];
ar[j]=tmp;
}
}
}
printf("\n Array in the Descending order is -\n");
for(i=1;i<=n;i++)
{
printf("\n%d",ar[i]);
}
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.