学渣小白 的学生作业:
#include
#define debug 0
#define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0)
int main(void) {
//DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10);
int i=6;
int factorial=1;
while(–i) {
factorial*=i;
DEBUG_PRINT (“i=%d\n”,i);
DEBUG_PRINT (“factorial=%d\n”,factorial);
DEBUG_PRINT("\n*************delimiter**************\n");
}
printf("factorial=%d\n",factorial);
return 0;
}
linux@linux:~/test01$ gcc 1j8practicer.c
linux@linux:~/test01$ ./a.out
factorial=120
linux@linux:~/test01$
#include
#define debug 1
#define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0)
int main(void) {
//DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10);
int passwd = 0,num_input=0;
int correct_password=123456;
do {
if (num_input>=3) {
printf(“GAME OVER!” “\n”);
return 1;
}else if (num_input!=0) {
printf(“You have already made mistakes with your password %d times, and there are %d more chances. Keep it up!\n”,num_input,3-num_input );
}
printf(“Please enter the password” “\n”);
scanf("%d", &passwd);
num_input++;
// 清除输入缓冲区
while (getchar() != ‘\n’); // 读取并丢弃直到换行符的所有字符
}while (correct_password!=passwd);
// 尊敬的艾欧尼亚最强王者,本网吧欢迎您!
printf("Dear Ionia, the strongest king of K, our internet cafe welcomes you!" "\n");
return 0;
}
linux@linux:~/test01$ gcc 1j81practicer.c
linux@linux:~/test01$ ./a.out
Please enter the password
dfdsf2134
You have already made mistakes with your password 1 times, and there are 2 more chances. Keep it up!
Please enter the password
sdfds23434
You have already made mistakes with your password 2 times, and there are 1 more chances. Keep it up!
Please enter the password
4324155
GAME OVER!
linux@linux:~/test01$ ./a.out
Please enter the password
fsgdfdsa
You have already made mistakes with your password 1 times, and there are 2 more chances. Keep it up!
Please enter the password
123456
Dear Ionia, the strongest king of K, our internet cafe welcomes you!
linux@linux:~/test01$