Thursday, 21 June 2012

write a c program to calculateaccept 10 number fromn user store these number into an array sort the array element in ascending order by using dynamic memory allocation


/*write a c program to calculateaccept 10 number fromn user store these number
into an array sort the array element in ascending order by using
dynamic memory allocation*/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *p,n,i,j,temp=0;
clrscr();
p=(int*)malloc(10 * sizeof(int));
printf("\nenter the element:\n");
for(i=0;i<10;i++)
scanf("%d",p+i);
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(*(p+i)>*(p+j))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
printf("\nthe element in ascending order:\n");
for(i=0;i<10;i++)
{
printf("%d\n",*(p+i));
}
getch();
}
/*
enter the element:                                                            
3                                                                            
9                                                                            
7                                                                            
6                                                                            
2                                                                            
4                                                                            
1                                                                            
3                                                                            
8                                                                            
5                                                                            
                                                                             
the element in ascending order:                                              
1                                                                            
2                                                                            
3                                                                            
3                                                                            
4
5
6
7
8
9

*/

No comments: