实验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/(2a);
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 7

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>
int main() {
int x,n,b=0;
for(x=101;x<=200;++x)
{
n=2;
for(n=2;n<x;n++) {
if(x%n0)
break;
}
if(n>=x)
{
printf("%d ",x);b++;
if(b%5
0)
printf("\n");}
}
printf("101~200内有%d个素数",b);

return 0;

}`

`#include<stdio.h>

include<math.h>

int main(){
int m,n,a,b;
printf("Enter a number is:");
while(scanf("%d",&a)!=EOF){
b=0;
n=0;
while(a>0){
m=a%10;
a=(a-m)/10;
if(m%2!=0){
n++;
b=b+m*pow(10,n-1);
}
}
printf("new number is :%d\n",b);
printf("Enter a number is:");
}
return 0;
}`

`#include<stdio.h>
int main(){
int n,m,a;
float s,q;

printf("Enter n(1~10):");
while(scanf("%d",&n)!=EOF){
	s=1;
	a=1;
 for(m=2;m<=n;m++){
     a=a*m*(-1);
     q=1.00/a;
     s=s+q;
 }
 printf("n=%d,s=%f",n,s);
 printf("\n");
 printf("Enter n(1~10):"); 

}
return 0;
}`

`#include<stdio.h>

include<stdlib.h>

include<time.h>

int main()
{
int a,
c,
i=1;
srand(time(0));
c=rand()%31;
printf("猜猜2020年12月哪一天会是你的luck day\n");
printf("开始喽,你有三次机会,猜吧(1~31)😊;
scanf("%d",&a);
while(i<3)
{
printf("你猜的日期早了,luck day还没到呢\n\n??(1~31)😊;
scanf("%d",&a);
i++;
}
while(i<3)
{
printf("你猜的日期晚了,luck day 悄悄溜到前面去啦\n\n??(1~31)😊;
scanf("%d",&a);
i++;
}
if(i3)
{
printf("次数用完了,正确是%d",c);
}
if(a
c)
{
printf("猜中啦,你的luck day是%d号",a);
i++;
}
return 0;
} `

posted @ 2020-11-23 19:45  亚托龙  阅读(59)  评论(0)    收藏  举报