# include <stdio.h>
# include <stdlib.h>
int getMax ( int n) ;
int getMin ( int n) ;
int range ( int n) ;
static int count= 1 ;
int main ( ) {
int num;
int i, j;
do {
printf ( "输入黑洞数:\n" ) ;
scanf ( "%d" , & num) ;
} while ( num< 100 || num>= 1000 ) ;
for ( i= 0 ; i< 3 ; i++ ) {
int temp_num= range ( num) ;
if ( temp_num== 495 || temp_num== 0 ) {
break ;
}
num= temp_num;
count++ ;
}
}
int getMax ( int n) {
int digits[ 3 ] ;
digits[ 0 ] = n/ 100 ;
digits[ 1 ] = n/ 10 % 10 ;
digits[ 2 ] = n% 10 ;
for ( int i= 0 ; i< 3 ; i++ ) {
for ( int j= 0 ; j< 3 - i- 1 ; j++ ) {
if ( digits[ j] < digits[ j+ 1 ] ) {
int temp= digits[ j] ;
digits[ j] = digits[ j+ 1 ] ;
digits[ j+ 1 ] = temp;
}
}
}
int max= digits[ 0 ] * 100 + digits[ 1 ] * 10 + digits[ 2 ] ;
return max;
}
int getMin ( int n) {
int digits[ 3 ] ;
digits[ 0 ] = n/ 100 ;
digits[ 1 ] = n/ 10 % 10 ;
digits[ 2 ] = n% 10 ;
for ( int i= 0 ; i< 3 ; i++ ) {
for ( int j= 0 ; j< 3 - i- 1 ; j++ ) {
if ( digits[ j] > digits[ j+ 1 ] ) {
int temp= digits[ j] ;
digits[ j] = digits[ j+ 1 ] ;
digits[ j+ 1 ] = temp;
}
}
}
int min= digits[ 0 ] * 100 + digits[ 1 ] * 10 + digits[ 2 ] ;
return min;
}
int range ( int n) {
printf ( "\n%d:%d-%d=%d\n" , count, getMax ( n) , getMin ( n) , getMax ( n) - getMin ( n) ) ;
return getMax ( n) - getMin ( n) ;
}
# include <stdio.h>
# include <stdlib.h>
char * str_copy ( char s1[ ] , char s2[ ] ) ;
int main ( ) {
char s1[ 50 ] ;
char s2[ 10 ] ;
int count = 0 ;
printf ( "输入s1字符串:\n" ) ;
scanf ( "%s" , s1) ;
printf ( "输入s2字符串:\n" ) ;
scanf ( "%s" , s2) ;
str_copy ( s1, s2) ;
printf ( "复制后的结果为:\n" ) ;
while ( s1[ count] != '\0' ) {
printf ( "%c" , s1[ count++ ] ) ;
}
}
char * str_copy ( char s1[ ] , char s2[ ] ) {
int count = 0 ;
int i = 0 ;
while ( s1[ i++ ] != '\0' ) ;
while ( s2[ count] != '\0' ) {
s1[ i- 1 ] = s2[ count++ ] ;
i++ ;
}
s1[ i+ count- 2 ] = '\0' ;
return s1;
}
# include <stdio.h>
int f ( int n) ;
int main ( ) {
int num;
printf ( "输入一个数:" ) ;
scanf ( "%d" , & num) ;
int res = f ( num) ;
printf ( "result=:%d" , res) ;
}
int f ( int n) {
if ( n == 1 ) {
return 1 ;
}
if ( n == 0 )
return 0 ;
return f ( n - 1 ) + f ( n - 2 ) ;
}
# include <stdio.h>
int isPrime ( int num) {
if ( num <= 1 ) return 0 ;
for ( int i = 2 ; i * i <= num; i++ ) {
if ( num % i == 0 ) {
return 0 ;
}
}
return 1 ;
}
int main ( ) {
FILE* file = fopen ( "zhishu.dat" , "w" ) ;
int count = 0 ;
printf ( "10000以内的质数:\n" ) ;
fprintf ( file, "10000以内的质数:\n" ) ;
for ( int i = 2 ; i <= 10000 ; i++ ) {
if ( isPrime ( i) ) {
count++ ;
printf ( "%-5d " , i) ;
fprintf ( file, "%-5d " , i) ;
if ( count % 10 == 0 ) {
printf ( "\n" ) ;
fprintf ( file, "\n" ) ;
}
}
}
printf ( "\n总共有%d个质数\n" , count) ;
fprintf ( file, "\n总共有%d个质数\n" , count) ;
fclose ( file) ;
return 0 ;
}