task1
点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 5
#define N1 397
#define N2 476
#define N3 21
int main()
{
int cnt;
int random_no,random_major;
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;
}
21 抽397到476的同学
25 0 21
随机抽取在座的5名同学
task2
点击查看代码
#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 = b*b - 4*a*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
点击查看代码
#include<stdio.h>
int main()
{
char a;
while( (scanf("%c",&a)) != EOF)
{
getchar();
if ( a == 'g' || a == 'G')
printf("go go go\n");
else if( a == 'y' || a == 'Y')
printf("wait a minute\n");
else if( a == 'r' || a == 'R')
printf("stop!\n");
else
printf("something must be wrong...\n");
}
return 0;
}
================================================================================================
task4
点击查看代码
#include<stdio.h>
int main()
{
double pay , sum = 0.0 , max=0.0 , min=20000.0;
printf("输入今天的开销直至-1终止\n");
while((scanf("%lf",&pay)) != EOF )
{
if(pay == -1)
break;
sum = sum + pay;
if(pay > max)
max = pay;
if(pay < min)
min = pay;
}
printf("最高一笔开销%lf\n最低一笔开销%lf\n一天总开销%lf\n",max,min,sum);
}
点击查看代码
#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 == b || a == c || b == c)
if(a == b && a ==c && b == c)
printf("等边三角形\n");
else
printf("等腰三角形\n");
else if ( a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a)
printf("直角三角形\n");
else
printf("普通三角形\n");
}
return 0;
}
=============================================================================================================
task6
点击查看代码
#include<stdio.h>
#define N 1
#define N1 30
int main()
{
int luck,i,gus;
i = 0;
srand(time(NULL));
luck = rand() % ( N1 - N + 1) + 1;
printf("开始喽,你有三次机会,猜吧(1~30):");
while ( i < 3 )
{
scanf("%d",&gus);
if (gus < luck)
printf("你猜的日期早了,你的luck日在后面哦\n");
else if(gus = luck)
{
printf("哇猜中了:)");
break;
}
else
printf("你猜的日期晚了,你的luck日在前面哦\n");
if (i < 2)
printf("在猜(1~30):");
else if(i == 2)
printf("次数用完了。偷偷告诉你,11月你的luck day是%d号哦",luck);
i++;
}
return 0;
}