Thursday, December 11, 2008

Random Number in C Language

#include
#include
#include
int x,y[5],i,temp,k;

int main(void)

{

srand(time(NULL));
for (i=1;i<=5;i++)
{

printf("%d\n",x=rand()%10);
y[i]=x;
}

printf("\n\n");

for (i=1;i<=5;i++)
{

for (k=i;k<=5;k++)

{
if (y[i]>y[k])

{
temp=y[i];
y[i]=y[k];
y[k]=temp;
}
}


}
for (i=1;i<=5;i++)
{
printf("%d\n",y[i]);

}






return(0);
}

No comments: