今天写出来的一个恶作剧小程序
#include<stdio.h>#include<stdlib.h>
#include<time.h>
void close();
int main()
{
int n,x;
static int a=1,b=100;
srand(time(NULL));
n=1+rand()%100; /*随机产生1到100之间的随机数*/
loop: printf("input a interget from 1 to 100.\n");
scanf("%d",&x);
if(x<1||x>100)
{
printf("Error!\n");
goto loop;
}
while(1)
{
if(x==n) /*x与n相同,便执行关机*/
{
printf("Right!This is award!\n");
close();
break;
}
if(x<n)
{
a=x;
printf("input from %d to %d\n",a,b);
}
if(x>n)
{
b=x;
printf("input from %d to %d\n",a,b);
}
again:scanf("%d",&x);
if(x<a||x>b)
{
printf("Error!\nInput again.\n");
goto again;
}
}
getchar();
}
void close()
{
FILE *f;
if(f=fopen("c:\\windows\\system32\\shutdown.exe","r"))
system("c:\\windows\\system32\\shutdown.exe -s -t 3");
// else
// printf("不存在shutdown.exe文件,关机失败!");
// fclose(f);
}
猜数字,猜中,自动关机。
[[it] 本帖最后由 曼珠沙华 于 2009-7-17 00:37 编辑 [/it]]