实现九九乘法表
int main ( )
{ int i = 0 ; int j = 0 ; for ( i = 1 ; i <= 9 ; i++ ) { for ( j = 1 ; j <= i; j++ ) printf ( "%d*%d=%d " , i , j, i* j) ; printf ( "\n" ) ;
} return 0 ;
}
猜数字的游戏设计
# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
void menu ( ) ;
void game ( ) ;
int main ( )
{ int input = 0 ; srand ( ( unsigned int ) time ( NULL ) ) ; do { menu ( ) ; printf ( "请选择>:" ) ; scanf ( "%d" , & input) ; switch ( input) { case 1 : game ( ) ; break ; case 0 : printf ( "退出游戏\n" ) ; break ; default : printf ( "输入错误\n" ) ; break ; } } while ( input) ; return 0 ;
}
void menu ( )
{ printf ( "**************************\n" ) ; printf ( "**************************\n" ) ; printf ( "*****请开始你的选择*******\n" ) ; printf ( " 1.begin 0.end \n" ) ; printf ( "**************************\n" ) ; printf ( "**************************\n" ) ; printf ( "**************************\n" ) ; printf ( "**************************\n" ) ;
}
void game ( )
{ int a = 0 ; int b = 0 ; a = rand ( ) % 100 + 1 ; while ( 1 ) { printf ( "请输入您想要输入的数字:\n" ) ; scanf ( "%d" , & b) ; if ( b < a) { printf ( "猜小了\n" ) ; } else if ( b > a) { printf ( "猜大了\n" ) ; } else { printf ( "恭喜你猜对了\n" ) ; printf ( " *** ***\n" ) ; printf ( " ***** *****\n" ) ; printf ( " ***********\n" ) ; printf ( " *********\n" ) ; printf ( " *******\n" ) ; printf ( " ***\n" ) ; break ; } }
}
素数判断
# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
int panduan ( int input) ;
int main ( )
{ int input = 0 ; printf ( "请输入想要的数字:\n" ) ; scanf ( "%d" , & input) ; int a = panduan ( input) ; if ( a == 0 ) { printf ( "不是 素数\n" ) ; } else { printf ( "是 素数 !" ) ; } return 0 ;
}
int panduan ( int input)
{ int i = 0 ; for ( i = 2 ; i < input; i++ ) { if ( input % i == 0 ) { return 0 ; } } return 1 ;
}
有序数组的查找
# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
int chaozhao ( int arr[ ] , int n, int sz) ;
int main ( )
{ int n = 0 ; int arr[ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 } ; int sz = sizeof ( arr) / sizeof ( arr[ 0 ] ) ; printf ( "请输入数字:\n" ) ; scanf ( "%d" , & n) ; int b= chazhao ( arr, n, sz) ; if ( b == 0 ) { printf ( "没找到" ) ; } else { printf ( "找到了并且下标是%d\n" , b) ; } return 0 ;
} int chazhao ( int arr[ ] , int n, int sz)
{ int left = 0 ; int right = sz - 1 ; while ( left <= right) { int mid = ( left + right) / 2 ; if ( n > arr[ mid] ) { left = mid + 1 ; } else if ( n < arr[ mid] ) { right = mid - 1 ; } else return mid; } return 0 ;
}
有序打印数字既递归的学习
# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
void digui ( int a) ;
int main ( )
{ int input = 0 ; printf ( "请输入想要输入的数字\n" ) ; scanf ( "%d" , & input) ; digui ( input) ; return 0 ;
} void digui ( int n)
{ if ( n > 9 ) { digui ( n / 10 ) ; } printf ( "%d " , n% 10 ) ;
}