实验三

#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.

");
        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

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

", 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("
");
        
        return 0;
}

#include <stdio.h> 
#include <stdlib.h> 
int main() 
{
    int i, j, n=0;
    for (i = 101; i <= 200;i++)
    {
        for (j = 2; j * j <= i;j++)   
            if(i%j==0)break;
        if(j*j>i)
        {
            printf("%5d", i);
            n++;
            if(n%5==0)printf("
");
        }
    }
    printf("
100~200之间一共有%d个素数
", n);
    return 0; 
} 

#include<stdio.h>
#include<stdlib.h>
int main()
{
    long a,b=0;
    int  i=1, c;
    printf("Enter a number:");
    while(scanf("%ld",&a)!=EOF)
    {
        i = 1, b = 0;
        while(a)
        {
            c = a % 10;
            a = a / 10;
            if(c%2)
            {
                b += c * i;
                i *= 10;
            }
        }
        printf("new number is:%ld

", b);
        printf("Enter a number:");
    }
    return 0; 
}

#include<stdio.h> 
#include<stdlib.h>
int main() 
{
    double s, i, n, x,sgn;
    printf("Enter n(1~10):");
    while(scanf("%lf", &n)!=EOF)
    {
        s = 0, x = 1;
        for (i = 1,sgn=1; i <=n;i++,sgn*=-1)
        {
            x *= i;
            s += (1 / x)*sgn;
        }
        printf("n=%d,s=%lf

",n,s);
        printf("Enter n(1~10):");
    }
    return 0; 
}

#include<stdio.h> 
#include<stdlib.h>
#include<time.h>
int main() 
{
    int random,i,j,n=3;
    srand(time(0));
    random = rand() % 31 + 1;
    printf("猜猜2020年12月哪一天会是你的lucky day

");
    printf("开始喽,你有三次机会,猜吧(1~31):");
    for (i = 0; i < n;i++)
    {  
        if(i)printf("再猜(1~31):");
        scanf("%d", &j);
        if(random==j)
        {
            printf("猜对啦!
");
            return 0;
        }
        else if(j<random)
            printf("你猜的日期早了,luck day还没到呢

");
        else
            printf("你猜的日期晚了,luck day悄悄溜到前面啦

");
    }
    printf("次数用完啦,偷偷告诉你:12月,你的lucky day是%d号
", random);
    return 0; 
}

原文地址:https://www.cnblogs.com/ruanfandd/p/13976894.html