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

 1 #include <stdio.h>
 2 #include <math.h>
 3 main()
 4     {
 5         int n,s,i,m;
 6         for(n = 101; n <= 200; n ++)
 7             {
 8                 s = sqrt(n);
 9                 for(i = 2; i <= s; ++ i)
10                 {
11                 if(n % i == 0)
12                 break;
13                 if(i == s)
14                 {
15                 m ++;
16                 printf("%d\t",n);
17                 if(m % 5 == 0)
18                 printf("\n");
19                 }
20                 }
21                 
22             }
23         printf("\n101~200之间共有%d个素数.",m);
24      } 

 1 #include<stdio.h>
 2 int main()
 3 {
 4     long long s,n,m;
 5     printf("Enter a number:");
 6     scanf("%ld",&s);
 7     printf("new number is: ");
 8     for(n = 1; s / n != 0; n *= 10 )
 9     ;
10     n /= 10;
11     for(; n >= 1; n /= 10)
12     {
13         m = s / n % 10;
14         if(m % 2 == 1)
15         printf("%ld",m);
16     }
17     return 0;
18 }

 1 #include <stdio.h>
 2 main()
 3 {
 4     int n,i;
 5     
 6     
 7     while(scanf("%d",&n) != EOF)
 8     {
 9     printf("Enter n(1~10): ");
10     double s = 0, t = 1;
11     if(n < 1 || n > 10)
12     printf("Invalid input.");
13     else
14     {
15     for(i = 1; i <= n; i ++, t *= i)
16     {
17         if(i % 2 == 1)
18         s += 1.0 / t;
19         else
20         s -= 1.0 / t;
21     }    
22     printf("n = %d, s= %f",n,s);
23     }
24     
25     }
26 }

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
    int x,y=1,z;
    printf("猜猜2020年12月哪一天会是你的lucky day\n");
    printf("开始喽,你有三次机会,开始猜吧(1~31):");
    srand(time(0));
    z=rand()%32;
    scanf("%d",&x);
    while(y<3){
        if(x==z)
        {
            printf("\n猜中啦!你的lucky day是%d号",z);
            break;
        }
        else if(x<z)
        {
            printf("\n你猜的日期早了,lucky day还在后面呢\n");
            y++;
        }
        else if(x>z)
    {
        printf("\n你猜的日期晚了,lucky day悄悄溜到前面啦\n");
        y++;
    }
    printf("\n再猜(1~31):");
    scanf("%d",&x);
    
    }
    if(y=3){
        printf("\n次数用完啦,偷偷告诉你,12月,你的lucky day是%d号\n",z);
    }
    return 0;

}

posted @ 2020-11-19 23:04  愚人欢  阅读(56)  评论(0编辑  收藏  举报