task1.c
`#include <stdio.h>

include <stdlib.h>

include <time.h>

define N 5

define N1 397

define N2 476

define N3 21

int main() {
int cnt;
int random_major, random_no;
srand(time(NULL));
cnt = 0;
while(cnt < N) {
random_major = rand() % 2;

     if(random_major) {
         random_no = rand() % (N2 - N1 + 1) + N1;
         printf("20248329%04d\n", random_no);
     }
     else {
         random_no = rand() % N3 + 1;
         printf("20248395%04d\n", random_no);
     }
     cnt++;
 }
 return 0;

}`

1.随机生成计算机类11班和12班的学号
2.随机生成奇安信班的学号
3.从三个班中随机抽取5个学生

task2.c
`#include <stdio.h>

include <math.h>

int main() {
double a, b, c;
double delta, p1, p2;
while(scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
if(a == 0) {
printf("a = 0, invalid input\n");
continue;
}
delta = bb - 4a*c;
p1 = -b/2/a;
p2 = sqrt(fabs(delta))/2/a;
if(delta == 0)
printf("x1 = x2 = %.2g\n", p1);
else if(delta > 0)
printf("x1 = %.2g, x2 = %.2g\n", p1+p2, p1-p2);
else {
printf("x1 = %.2g + %.2gi, ", p1, p2);
printf("x2 = %.2g - %.2gi\n", p1, p2);
}
}
return 0;
}`

task3.c

#include<stdio.h> int main(){ char a; while(scanf("%c",&a)!=EOF){ getchar(); if(a == 'r') printf("stop!\n"); else if(a == 'g') printf("go go go\n"); else if(a == 'y') printf("wait a minute\n"); else printf("something must be wrong...\n"); } return 0; }

task4.c

#include<stdio.h> int main(){ double a,total,max=0; double min=20000; printf("输入今日开销,直到输入-1为止:\n"); while(scanf("%lf",&a)!=EOF){ if(a==-1) break; total+=a; if(a>max) max=a; if(a<min) min=a; } printf("今日累计消费总额:%.1f\n",total); printf("今日最高一笔开销:%.1f\n",max); printf("今日最低一笔开销:%.1f\n",min); return 0; }

task5.c

#include<stdio.h> int main(){ int a,b,c; while(scanf("%d %d %d",&a,&b,&c)!=EOF){ if(a+b<c||a+c<b||b+c<a) printf("不能构成三角形\n"); else if(a*a+b*b==c*c) printf("直角三角形\n"); else if(a==b&&b==c) printf("等边三角形\n"); else if(a==b||b==c||a==c) printf("等腰三角形\n"); else printf("普通三角形\n"); } return 0; }

task6.c

`#include<stdio.h>

include<stdlib.h>

include <time.h>

int main(){
int lucky_day=rand()%31;
int n,day;
printf("猜猜哪天是你的lucky day\n\n开始喽,你有三次机会,猜吧(1~30):");
for(n=0;n<3;n++){
scanf("%d",&day);
if(day>lucky_day) printf("\n你猜的日期晚了,你的lucky day在前面哦\n\n再猜(1~30):");
else if(day<lucky_day) printf("\n你猜的日期早了,你的lucky day在后面哦\n\n再猜(1~30):");
else {
printf("猜对了!");
break;
}
}
if(n==3){
printf("次数用光喽,偷偷告诉你,你的lucky day是%d号",lucky_day);
}
return 0;
}`