C Graphics :
C Programming Tutorials
C-programming is the base of Computer programming.
Sorting An Array
Accept 10 numbers and store in an array, print sorted array in descending and ascending order:
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<10;i++)
printf(" %d ",a[i]);
printf(" Nos sorted in ascending order\n");
printf("\n");
for(i=9;i>=0;i--)
printf(" %d ",a[i]);
printf(" Nos sorted in descending order\n");
getch();
}
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<10;i++)
printf(" %d ",a[i]);
printf(" Nos sorted in ascending order\n");
printf("\n");
for(i=9;i>=0;i--)
printf(" %d ",a[i]);
printf(" Nos sorted in descending order\n");
getch();
}
Subscribe to:
Posts (Atom)
Related Post
Array:
String functions:
General (Loops-for/while)