You are here: Foswiki>Main Web>TWikiUsers>DorotaP>ProgramiK (revision 1)EditAttach
Program sortuje tablice.

//sortowanie//

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

#define SIZE 10

int main(int argc,char*argv[])

{

float tab[SIZE],min;

int i,j,stime;

long ltime;

ltime=time(NULL);

stime=(unsigred) ltime;

srand(stime);

for(i=0;i<SIZE;i++)

{

tab[i]=(float)rand()/RAND_MAX;

printf("tab[%d]=%f\n",i,tab[i]);

}

j=0;

for(i=0;i<SIZE;i++)

if(tab[i]<tab[j])

j=i;

min=tab[0];

tab[0]=tab[j];

tab[j]=min;

for(i=1;i<SIZE;i++)

{

min=tab[i];

j=j-1;

while(j>0 && tab[j]>min)

{

tab[j+1]=tab[j];

j--;

}

tab[j+1]=min;

}

printf("\n");

printf("posortowane:\n");

printf("\n");

for(i=0;i<SIZE;i++)

printf("tab[%d]=%f\n",i,tab[i]);

getchar();

return 0;

}
Edit | Attach | Print version | History: r4 < r3 < r2 < r1 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r1 - 22 May 2004, DorotaP
 
This site is powered by FoswikiCopyright © CC-BY-SA by the contributing authors. All material on this collaboration platform is copyrighted under CC-BY-SA by the contributing authors unless otherwise noted.
Ideas, requests, problems regarding Foswiki? Send feedback