实验三

#include <math.h>
#include <stdio.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)
printf("not quadratic equation.\n\n");
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; // 生成一个0~9之间的随机整数
printf("%3d", x);
}while(n<N);
printf("\n");
return 0;
}

  

#include <stdio.h>
#include <math.h>
int main()
{
    int m,n,p=0;
    for(n=101;n<=200;n++)
    {
        for(m=2;m<(sqrt(n));m++)
            if(n%m==0)
			break;
        if(m>(sqrt(n)))
            {
                p++;printf("%4d",n);
                if(p%5==0)
                    printf("\n");
                
            }
    }
    printf("\n101~200之间共有%d个素数",p);
    return 0;
}

  

#include <stdio.h>
#include <math.h>
int main()
{
    long int s,n=0,m=0,t=0;
    printf("Enter a number: ");
    while(scanf("%ld",&s)!=EOF)
    {
        while(s!=0)
        {
            m=s%10;
            if(m%2==1)
            {
                n++;
                t=m*pow(10,n-1)+t;
                    
            }
            s=s/10;
        }
        printf("new number is: %ld\n\n",t);
        printf("Enter a number: ");
        
        t=0;
        n=0;
    }
    return 0;
}

  

#include <stdio.h>
#include <math.h>
int main()
{
    int n,i,p=1;
    
    double s;
    
    printf("Enter n(1~10): ");
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            p=p*i;
            s=s+pow(-1,i-1)*1.0/p;
        
        }
    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;
	int m;

	
	
	srand(time(0));
	x=rand()%32+1;
	printf("猜猜20220年12月哪一天会是你的lucky day\n");
	
	printf("你有三次机会,猜吧(1~31):");
	
	scanf("%d",&m);

	if(m<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(m>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
	int i;
   if(x!=m){
   	printf("再猜啦(1~31):");
   	scanf("%d",&i);
   	if(i<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(i>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
   	
   	 }
   	 int l;
   	 if(x!=i&&x!=m){
   	 	printf("再猜啦(1~31):");
			scanf("%d",&l);
			if(l<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(l>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
		}
		if(x!=l&&x!=m&&x!=i){
			printf("次数用完啦,偷偷告诉你,你的lucky day是:%d",x);
		}
	  
	
	return 0;
} 

  

posted @ 2020-11-15 16:52  yourknight  阅读(72)  评论(2)    收藏  举报