实验三 头大


#include<stdio.h>
#include<math.h>
int main()
{
    double s=1;
    int n;
    int k=-1;
    double x=1;
    printf("Enter N: ");
    while(scanf("%d",&n)!=0)
    {
    for(int i=2;i<=n;i++)
    {
        x*=i;
        s+=1/x*k;
        k*=-1;
    }
    printf("%lf",s);
    }
    return 0;
 } 

 

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

// 一元二次方程求解
// 重复执行, 直到按Ctrl+Z结束
//
#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;
} 

// 生成N个0~9之间的随机整数,并打印输出
#include <stdio.h>
#include <stdlib.h>
#include <time.h>#define N 6
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 j,i,k,n=0;
    for(j=101;j<=200;j=j+2)
    {
        k=sqrt(j);
        for(i=2;i<=k;i++)
        if(j%i==0)
            break;
        if(i>=k+1)
        {
            printf("%d",j);
            n=n+1;
        }
        if(n%n==0)
            printf("\n");
    }
    printf("\n");
    return 0;
}

#include<stdio.h>
int main()
{
    long int s; 
    long int a=0;
    int j=1;
    printf("Enter the number: ");
    scanf("%ld",&s);
    for(int i=32;i>0;i++) 
    {
        int temp=s%10;
        if(temp%2!=0) 
        {
        a+=temp*j; 
        j*=10; 
         }
        s/=10; 
     } 
    printf("New number is: %ld",a);
    
    
    return 0;
}

posted @ 2020-11-19 23:10  RANJX  阅读(110)  评论(0)    收藏  举报