标签:color += day efi sqrt print class fine i++
实验1
#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; }
实验2
#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; }
实验3
#include<stdio.h> #include<math.h> int main() { int n=101; int i=2,k=0; for(n=101;n<=200;++n) { for(i=2;i<=n/2;++i) if(n%i==0)break; if(i>n/2) { printf("%d\t",n); k+=1; } } printf("\n一共有%d个素数",k); }
实验4 #include<stdio.h> int main(){ long s,m,n; float i; i=0.1; n=0; printf("Enter a number:"); scanf("%ld",&s); while(s>0){ m=s%10; s=s/10; if(m%2!=0){ i=10*i; n=n+m*i; } } printf("new number is%d",n); return 0 ; }
实验5 #include<stdio.h> int main() { int n; int i=1; float s=0,h=1; printf("Enter n(1~10):"); while(scanf("%d",&n)!=EOF){ for(;i<=n;i++) { h=h*i; if(i>=2)h=-1*h; s=s+1/h; } printf("n=%d,s=%f\n",n,s); printf("Enter n(1~10):"); return 0; }
实验6 #include<stdio.h> #include<stdlib.h> #include<time.h> int main(){ int x,i,a; srand(time(0)); x=rand()%31+1; printf("猜猜十二月那一天是你的lucyday\n猜吧,开始喽(1~31)\n"); for(i=1;i<=3;i++) { scanf("%d",&a); if(a==x){ printf("恭喜你猜对了"); break; } if(a>x) printf("你猜的日子晚了,luck day悄悄溜到前面了\n"); if(a<x) printf("你猜的日子早了,luck day还没到呢\n"); } if(i>3) printf("次数用完啦,偷偷告诉你:12月你的Lucy day是:%d号",x); return 0; }
标签:color += day efi sqrt print class fine i++
原文地址:https://www.cnblogs.com/zpp6/p/13983854.html