# 实验三

```#include<stdio.h>
#include<math.h>

int main(){
float a, b, c, x1, x2;
float delta, real, imag;

printf("Enter a, b, c:  ");

while(scanf("%f%f%f", &a, &b, &c)!=EOF){
if(a == 0)
else{
delta = b*b - 4*a*c;

if(delta >= 0){
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("x1 = %.2f, x2 = %.2f\n\n", x1, x2);
}
else{
real = -b / (2*a);
imag = sqrt(-delta) / (2*a);
printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n\n", real, imag, real, imag);
}
}

printf("Enter a, b, c:  ");
}

return 0;
}```

```#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 5

int main(){
int x, n;

srand(time(0));
n = 0;
do{
n++;
x = rand()%10;
printf("%3d", x);
}while(n < N);

printf("\n");

return 0;
}```

```#include<stdio.h>
#include<math.h>

int main()
{
int N, n;
int count = 0;

for(N = 101; N <= 200; N++)
{
for(n = 2; n <= sqrt(N); n++)
{
if(N%n == 0)
break;
}
if(n > sqrt(N))
{
printf("%4d", N);

count++;//统计素数的个数

if(count%5 == 0)// 每行输出五个数字
printf("\n");
}
}
printf("\n");
printf("101~200之间有%d个素数\n", count);

return 0;
} ```

```#include<stdio.h>
#include<math.h>

int main()
{
long int s;

printf("Enter a number:");

while(scanf("%ld", &s) != EOF)
{
int i = 1;
long int k = 0;
int m = 0;

printf("new number is:");

while(s)  //当s不为0时，表达式为真，执行循环
{
i = s%10;  //取s最后一位
s /= 10;
if(i%2 == 0)
continue;    //跳过偶数
k += pow(10,m)*i;
m++; //通过计算循环的次数来确定奇数的位置
}
printf("%ld", k);
printf("\n\n");
printf("Enter a number:");
}

return 0;
}```

```#include<stdio.h>
#include<math.h>

int main(){
int n, i;
int k;
double s;

printf("Enter n(1~10): ");

while(scanf("%d", &n) != EOF) {
k = 1;
s = 0;
for(i = 1; i <= n; i++)
{
k *= i;
s += 1.0*pow(-1,i-1)/k;
}

printf("n = %d, s = %lf\n\n", n, s);
printf("Enter n(1~10): ");
}

return 0;
}```

```#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main()
{
int x, i;
int date;

srand(time(0));
x = rand()%31;

printf("猜猜2020年12月哪一天会是你的lucky day\n\n");
printf("开始喽，你有三次机会，猜吧（1~31）：");

for(i = 1; i <= 3; i++)
{
scanf("%d", &date);
printf("\n");
if(x == date)
{
printf("恭喜你猜对了！\n");
break;
}
else if(x > date)
printf("你猜的日期早了，lucky day还没到呢\n\n");
else
printf("你猜的日期晚了，lucky day悄悄溜到前面啦\n\n");

if(i != 3)
printf("再猜（1~31):");
}
if(i == 4)
printf("次数用完啦。偷偷告诉你，你的lucky day是%d号\n", x);

return 0;
} ```

(0)
(0)