#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<stdlib.h>
#include<math.h>
int main()
{
int n;
int i,l;
int h=0;
for(n=101;n<=200;n++)
{
for(i=2; i<=sqrt(n); i++)
{
if(n%i == 0)
break;
}
if(i>sqrt(n))
{
h++;
printf("%d ",n);
l++;
if(l%5==0)
printf("\n");
}
}
printf("\n101~200之间共有%d个素数",h);
return 0;
}
![]()
#include<stdio.h>
#include<stdlib.h>
int main() {
int a,b,n;
printf("Enter a number:");
while(scanf("%d",&n)!=EOF)
{
int c=0,i=1;
while(n >= 1)
{
a = n%10;
n = n/10;
if(a%2 == 0);
else
{
c = c+a*i;
i = i*10;
}
}
printf("new number is :%d\n\n",c);
printf("Enter a number:");
}
return 0;
}
![]()
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n, i, j;
double s = 0, b;
printf("Enter n(1~10):");
while(scanf("%d", &n)!=EOF)
{
if(n >= 1 && n <= 10)
{
for(i = 1; i <= n; i++)
{
int t = 1;
for(j = 1; j <= i; j++)
t = t*j;
b = 1.0/t;
if(i%2 == 0)
b = (-1)*b;
s = s+b;
}
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 b,c = 1;
srand(time(0));
int a = rand()%30+1;
printf("猜猜2020年12月哪一天会是你的luck day\n\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
scanf("%d",&b);
while(c <= 3)
{
if(c <= 3&&c!=1)
{
printf("\n再猜(1~31):") ;
scanf("%d",&b);
}
if(b > a)
printf("\n你猜的日期晚了,luck day悄悄溜到前面啦\n\n");
else
if(b == a)
printf("\n答对了\n");
else
printf("\n你猜的日期早了,luck day还没到呢\n\n");
c++;
}
printf("\n次数用完啦。偷偷告诉你:12月,你的luck day是%d号\n",a);
return 0;
}
![]()