实验3

------------恢复内容开始------------

#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>
int main() {
int i,j,n=0;
for(i=101;i<200;i++)
{
    for(j=2;j<i;j++){
    if(i%j==0)break;
    }
    if(j>=i){
        printf("%4d",i);
        n++;
    if(n%5==0){
    printf("\n");
    }
}
}
printf("\n101~200之间共有%d个素数",n);
return 0;
}

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

1:%2

2:   pow

#include<stdio.h>
#include
<math.h> int main(){ double s; int n,x,y,a,b; printf("Enter n(1~10):"); while(scanf("%d",&n)!=EOF){ s=0; b=1; for(x=1;x<=n;x++){ for(a=2;a<=x;++a){ b=b*a; } y=pow(-1,x-1); s=s+1.0/b*y; b=1; } printf("n=%d,s=%.6f\n",n,s); printf("\n"); printf("Enter n(1~10):"); } return 0; #include<stdio.h>

 

 

 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){

    int x=0,n=0;
    
    srand(time(0));
    while(x==0){
    x=rand()%31;
    }
    for(int i=0;i<3;i++){
        scanf("%d",&n);
        if(n==x){
        
            printf("靠骗,靠偷袭!小伙子你不讲武德!!");
            break;
        }
        if(n<x){
            printf("我大意了啊,没有闪");
        }
        if(n>x){
            printf("很快啊!");
        }
        printf("\n");
        if(i==2){
            printf("年轻人,传统功夫以点到为止。告诉你吧这个数是%d!",x);
        }
    }
    return 0;
}

 

posted @ 2020-11-15 13:42  我想转专业  阅读(79)  评论(0)    收藏  举报