C库函数 - memcmp() #include <stdio.h> #include <string.h> int main () { char str1[15]; char str2[15]; int ret; memcpy(str1, "abcdef", 6); memcpy(str2, "ABCDEF", 6); ret = memcmp(str1, str2, 5); if(ret > 0) { printf("str2 is less than str1"); } else if(ret < 0) { printf("str1 is less than str2"); } else { printf("str1 is equal to str2"); } return(0); }
C库函数 - srand() #include <stdio.h> #include <stdlib.h> #include <time.h> int main () { int i, n; time_t t; n = 5; /* Intializes random number generator */ srand((unsigned) time(&t)); /* Print 5 random numbers from 0 to 50 */ for( i = 0 ; i < n ; i++ ) { printf("%d\n", rand() % 50); } return(0); }
C库函数 - rand() #include <stdio.h> #include <stdlib.h> int main () { int i, n; time_t t; n = 5; /* Intializes random number generator */ srand((unsigned) time(&t)); /* Print 5 random numbers from 0 to 49 */ for( i = 0 ; i < n ; i++ ) { printf("%d\n", rand() % 50); } return(0); }
C库函数 - labs() #include <stdio.h> #include <stdlib.h> int main () { long int a,b; a = labs(65987L); printf("Value of a = %ld\n", a); b = labs(-1005090L); printf("Value of b = %ld\n", b); return(0); }
C库函数 - abs() #include <stdio.h> #include <stdlib.h> int main () { int a, b; a = abs(5); printf("value of a = %d\n", a); b = abs(-10); printf("value of b = %d\n", b); return(0); }