#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 <math.h>
int fun(int n)
{
int i;
if (n==2||n==3)
return 1;
for (i=2;i<=sqrt(n);i++)
{
if (n%i==0)
return 0;
}
return 1;
}
int main()
{
int i,j=0,n;
for (n=101;n<=200;n++)
{
if (fun(n)==1)
{
printf("%d\n",n);
j++;
}
}
printf("101-200之间共有%d个素数",j);
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>
double fun(int n)
{
int i;
double sum=1;
for (i=1;i<=n;i++)
sum*=i;
return sum;
}
int main()
{
int n,i;
double s=0;
printf("Enter n(1~10):");
while(scanf("%d",&n)!=EOF)
{
s=0;
for (i=1;i<=n;i++)
{
if(i%2==0)
s-=1.0/fun(i);
else
s+=1.0/fun(i);
}
printf("n=%d,s=%lf\n",n,s);
printf("Enter n(1~10):");
}
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int x, n,i,j,k;
srand(time(NULL));
x = rand()%31+1;
printf("猜一猜20202年12月那一天是你的luck day\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
for (i=0;i<=2;i++)
{
scanf("%d",&n);
if (n>x)
printf("你猜的日期晚了,lucky day 悄悄溜到前面啦!\n");
else if (n<x)
printf("你猜的日期早了,lucky day 还没到呢!\n");
else
{
printf("你猜对啦!\n");
return 0;
}
printf("再猜:");
}
printf("次数用完啦,悄悄告诉你,12月,你的lucky day是:%d\n",x);
return 0;
}