#include <stdlib.h>
#include <time.h>
static void guess(int number, int *count)
{
int n
do
{
scanf("%d", &n)
if ( n >number )
{
printf("Your answer is HIGHER, try again.\n")
}else if ( n <number )
{
printf("Your answer is LOWER, try again.\n")
}
++*count
}while ( n != number )
}
int main(int argc, char *argv[])
{
int number
int count = 0
srand((unsigned int) time(NULL))
while ( count <15 )
{
number = rand()%100 + 1
guess(number, &count)
if ( count <= 7 )
{
printf("congratulation.\n")
}
else if ( count >7 &&count <15 )
{
printf("You can do it better.\n")
}
}
printf("I can’t bare it.\n")
}
1.定义一个输出函数viod printMsg(char* msg1,int num1,char* msg2, int num2)
{
int i
for(i =0i <num1i++)
{
printf("%s",msg1)
}
第二个信息可以复制上面的,手机打的代码,不方便
}
2.和第一题类似,定义一个函数,然后循环调用。
3.函数嵌套调用
思路:定义one_three函数,第一行打印one,第2行调用two函数,再定义two函数,里面放一个打印three的语句,最后用main函数,打印开始语句,调用one_three函数,打印完成语句。
问题很初级,兄弟好好学,前景还不错的。