#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>
int main(){
int n,i,z,q1,m=0;
for(n=100;n<=200;n++){
for(i=2;i<n;i++){
z=n%i;
if(z==0){
q1=0;
break;
}
}
if(z!=0){
q1=1;
}
if(q1!=0){
m++;
printf(" %d",n);
if(m%5==0)printf("\n");
}
}
printf("\n");
printf("100~200之间共有%d个素数",m);
return 0;
}
![]()
#include<stdio.h>
#include<math.h>
int main(){
long s,t;
int n,m;
printf("Enter a number:");
while(scanf("%ld",&s)!=EOF){
m=0;
t=0;
while(s!=0){
n=s%10;
if(n%2!=0){
t=pow(10,m)*n+t;
m++;
}
s=s/10;
}
printf("new number is:%d",t);
printf("\n");
printf("\n");
printf("Enter a number:");
}
return 0;
}
![]()
#include<stdio.h>
#include <math.h>
int main(){
double s;
int n,x,y,a,b;
printf("Enter n(1~10):");
while(scanf("%d",&n)!=EOF){
s=0;
b=1;
y=-1;
for(x=1;x<=n;x++){
for(a=2;a<=x;++a){
b=b*a;
}
y=pow(-1,x-1);
s=s+(double)1/b*y;
b=1;
}
printf("n=%d,s=%.6f\n",n,s);
printf("\n");
printf("Enter n(1~10):");
}
return 0;
}
![]()
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
int date,a,n=3;
srand(time(0));
date=rand()%31;
printf("猜猜2020年12月哪一天会是你的luck day\n");
printf("\n");
printf("开始喽,你有三次机会,猜吧(1~31): ");
while(n--){
scanf("%d",&a);
if(a<date){
printf("\n");
printf("你猜的日期早了,luck day还没到呢\n");
printf("再猜(1~31):");
}
else if(a>date){
printf("\n");
printf("你猜的日期晚了,luck day悄悄溜到前面啦\n");
printf("再猜(1~31):");
}
while(a==date){
printf("\n");
printf("年轻人不讲武德,猜中了,耗子尾汁\n",date);
return 0;
}
}
if(n==-1){
printf("次数用完啦,偷偷告诉你:12月,你的lucky day是%d号\n",date);
}
return 0;
}
![]()