一顿操作猛如虎,一看头发。。。

#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; 
        printf("%3d", x);
    }while(n<N);
    
    printf("\n");
    
    
    return 0;
}

#include <stdio.h> 
#include <math.h>
int main(){
    int x,m,a=0;
     for(x=100;x<=200;x++){
         
        m=2;
        for(m=2;m<x;m++) {
            if(x%m==0)
            {break;    }}
    if(m>=x) {
        printf("%d ",x);a++;
        if(a%5==0)
        printf("\n");}
    }
    printf("100~200内有%d个素数",a);
return 0;

}

#include<stdio.h>
int main() {
    int a,s,t,m;
    m = 1;
    t = 0;

    printf("Enter a number: ");
    while (scanf("%d", &s) != EOF) {

        while (s >= 1) {
            a = s % 10;
            s = s / 10;
            if (a % 2 != 0) {
                 t = t + a * m;
                m = m * 10;
} }

    printf("new number is %d\n", t);
    printf("Enter a number: ");
    t = 0;
    m = 1;
 }
return 0;
}

#include<stdio.h>
#include<math.h>
int main() {
    int i=1;
    int n;
    float s=0,h=1;
    printf("Enter n(1~10):");
    while(scanf("%d",&n)!=EOF) {
        for(;i<=n;i++) {
            h=h*i; 
            if(i>=2) h=-1*h;
            s=s+1/h;
}
    printf("n=%d,s=%f\n",n,s);
    printf("Enter n(1~10):");
}
}

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int a,x,y=1;
    srand(time(0));
    x=rand()%31+1;
    printf("猜猜12月的lucky day\n");
    printf("有三次机会哦 ready go: ");
    scanf("%d",&a);
    while(y<3)
    {    
        if(a==x)
        {
            printf("congratulation you are right!\n");
            break;
        }
            else if(a>x)
            printf("不想让幸运日早点到来吗\n");
            else
            printf("太早了哦,幸运日还在等你\n"); 
            printf("再猜(1~31):  ");
            scanf("%d",&a);
            y++;
    }
    if (y>=3)
    printf("好可惜啊,偷偷告诉你,你的幸运日是:%d",x);
    return 0;
} 

总结·:

大致了解循环语句使用,算法逻辑和格式符

疑问:

实验5里的math头文件是不是不必要的

posted @ 2020-11-19 22:12  海科zhh  阅读(36)  评论(2编辑  收藏  举报