int main(void) { int values[SIZE] = {1,2,3,4,5,6,7,8,9,10}; int target[SIZE]; double curious[SIZE / 2] = {1.0, 2.0, 3.0, 4.0, 5.0}; puts("memcpy() used: "); puts("values (original dara):"); showarray(values,SIZE); memcpy(target,values,SIZE * sizeof(int)); puts("target (copy of values):"); showarray(target,SIZE); puts("\nUsing memmove() with overlapping ranges:"); memmove(values + 2, values, 5 * sizeof(int)); puts("values -- elements 0-5 copied to 2-7"); showarray(values,SIZE); puts("\nUsing memcpy() to copy double to int:"); memcpy(target, curious, (SIZE/2) * sizeof(double)); puts("target -- 5 double into 10 int positions:"); showarray(target,SIZE); return 0; }
int main() { double vals[NUM]; fillarray(vals, NUM); puts("Random list: "); showarray(vals, NUM); qsort(vals, NUM, sizeof(double), mycomp); puts("\nSorted list: "); showarray(vals, NUM); return 0; }
int main() { double data[LEN]; double cdata[LEN]= {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 7.7, 1.1}; int index; srand((unsigned int) time(0)); //reset seed for (index=0; index<LEN; index++) { data[index] = ((double) rand()+1.0)/((double) rand()); } qsort(data, LEN, sizeof(double), mycomp); showarray(data); long int start1, end1; start1 = clock(); peak1(data); end1 = clock(); printf("run time for peak1: %ldms\n", end1-start1); long int start2, end2; start2 = clock(); peak2(data, data+LEN); end2 = clock(); printf("run time for peak2: %ldms\n", end2-start2); return 0; }
int main(){ unsigned int i; for (i=1; i<=N; i++){ array[i]= rand(); } sort(1,N,array); showarray(array); return 0; }
int main() { double data[LEN][LEN]; double cdata[11][11]= { { 4.1, 5.1, 6.1, 7.1, 8.1, 7.1, 6.1, 5.1, 4.1, 3.1, 2.1}, { 5.0, 6.1, 7.1, 8.1, 9.1, 8.1, 7.1, 6.1, 5.1, 4.1, 3.1}, { 6.0, 7.1, 8.1, 9.1, 10.1, 9.1, 8.1, 7.1, 6.1, 5.1, 4.1}, { 7.0, 8.1, 9.1, 10.1, 11.1, 10.1, 9.1, 8.1, 7.1, 6.1, 5.1}, { 8.1, 9.1, 10.1, 11.1, 12.1, 11.1, 10.1, 9.1, 8.1, 7.1, 6.1}, { 7.1, 8.2, 9.2, 10.2, 11.2, 10.1, 9.2, 8.1, 7.2, 6.1, 5.1}, { 6.1, 7.2, 8.1, 9.1, 10.1, 9.1, 8.1, 7.1, 6.2, 5.3, 4.1}, { 5.1, 6.2, 7.3, 8.2, 9.1, 8.2, 7.1, 6.3, 5.1, 4.2, 3.3}, { 4.1, 5.3, 6.1, 7.2, 8.1, 7.3, 6.1, 5.2, 4.1, 3.1, 2.1}, { 3.1, 4.3, 5.1, 6.1, 7.3, 6.1, 5.1, 4.1, 3.3, 2.1, 1.1}, { 2.1, 3.3, 4.1, 5.1, 6.1, 5.1, 4.3, 3.1, 2.1, 1.1, 0.1}}; int ir, ic; srand((unsigned int) time(0)); //reset seed for (ir=0; ir<LEN; ir++) { for(ic=0; ic<LEN; ic++) //data[ir][ic] = data[ir][ic-1]+1; data[ir][ic] = ((double) rand()+1.0)/((double) rand()); } //data[666][666] = 9999999; //sometimes peak2 cannot find peak //qsort(data, LEN, sizeof(double), mycomp); showarray(data); long int start1, end1; start1 = clock(); peak1(cdata); end1 = clock(); printf("run time for peak1: %ldms\n", end1-start1); long int start2, end2; start2 = clock(); peak2(cdata, 0, LEN); end2 = clock(); printf("run time for peak2: %ldms\n", end2-start2); return 0; }
int main() { int n,m,l, i,j,k,C; v[0] = c[0]; v[1] = c[1]; u = v; t = d[0]; showarray(a); printf(":-> ");showarray(w); printf("\n"); showarray(b); printf(":-> ");showarray(x); printf("\n"); showarray(c); printf(":-> ");showarray(y); printf("\n"); showarray(d); printf(":-> ");showarray(z); printf("\n"); printf("14 :-> %d\n" "[Hello, world!] :-> [%s]\n",sizeof(yell),yell); printf("%d :-> %d\n", sizeof(names1)/sizeof(char*), sizeof(names2)/sizeof(names2[0])); for(i=0;i<sizeof(names1)/sizeof(char*);++i) printf("%s :-> %s\n", names1[i],names2[i]); for(i=0;i<3;++i) printf("%d %d ",ab[i].a,ab[i].b); printf(":-> 1 2 3 4 5 0\n"); for(i=0;i<3;++i) printf("%g %g ",fab[i].a,fab[i].b); printf(":-> 1 0 2 0 3 0\n"); for(i=0;i<4;++i) printf("%d %d ",sab[i].a,sab[i].b); printf(":-> 1 2 3 4 5 6 7 0\n"); printf("%c%c%c :-> abc\n",un[0].a, un[1].a, un[2].a); printf("%d%d%d :-> %d%d%d\n" "%d%d%d :-> %d%d%d\n", v[0][0],v[0][1],v[0][2],c[0][0],c[0][1],c[0][2], u[1][0],u[1][1],u[1][2],c[1][0],c[1][1],c[1][2]); printf("%d%d%d%d :-> %d%d%d%d\n", t[0],t[1],t[2],t[3],d[0][0],d[0][1],d[0][2],d[1][0]); n = sizeof(_3d)/sizeof(_3d[0]); m = sizeof(_3d[0])/sizeof(_3d[0][0]); l = sizeof(_3d[0][0]); printf("%d, %d, %d :-> 2, 2, 5\n",n, m, l); for(i=0;i<n;++i) { printf(":"); for(j=0;j<m;j++) { printf(":"); for(k=0;k<l;k++) { C = _3d[i][j][k]; printf("%c",C>0?C:'0'); } } } printf(" :-> ::TooLo:00000::Me000:Yes00\n"); return 0; }