ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

实验三

2020-11-15 17:03:44  阅读:147  来源: 互联网

标签:%. int lucky 实验 printf include day


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

  

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

  

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

  

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

	
	
	srand(time(0));
	x=rand()%32+1;
	printf("猜猜20220年12月哪一天会是你的lucky day\n");
	
	printf("你有三次机会,猜吧(1~31):");
	
	scanf("%d",&m);

	if(m<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(m>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
	int i;
   if(x!=m){
   	printf("再猜啦(1~31):");
   	scanf("%d",&i);
   	if(i<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(i>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
   	
   	 }
   	 int l;
   	 if(x!=i&&x!=m){
   	 	printf("再猜啦(1~31):");
			scanf("%d",&l);
			if(l<x){
		printf("你猜的日期早啦,lucky day还没到呢\n");
	}
	else if(l>x){
		printf("你猜的日期晚啦,lucky day悄悄溜到前面啦\n");
	}
	else{
		printf("这就是你的lucky day啦");
	}
		}
		if(x!=l&&x!=m&&x!=i){
			printf("次数用完啦,偷偷告诉你,你的lucky day是:%d",x);
		}
	  
	
	return 0;
} 

  

标签:%.,int,lucky,实验,printf,include,day
来源: https://www.cnblogs.com/yourknight/p/13977363.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有