标签:mamicode lse day span 等于 fine rand ble mic
#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 main() { int m,k,n; k=0; for(n=101;n<=200;n++) { for(m=2;m<=sqrt(n);++m) if(n%m==0)break; if(m>sqrt(n)) { printf("%d\t",n); k++; if(k%5==0) printf("\n"); } } printf(" \n"); printf("101^200之间共有%d个素数",k); return 0; }
#include<stdio.h> int main(){ int s,n,t=0; float a=0.1; printf("Enter a number:%ld",s); scanf("%ld",&s); while(s>0){ n=s%10; s=s/10; if(n%2!=0){ a=a*10; t=n*a+t; } } printf("new number is:%ld",t); return 0; }
思路:将输入的数对10取余得到个位数,然后将输入的数被十整除再对十取余得到十位数,以此类推,将各个位数对2取余若不等于零则为奇数
将第一个得到的奇数乘以a(a=1),然后将a乘10,再把第二个得到的奇数乘以a(a=10),再把a乘以10·····以此类推。
#include <stdio.h> #include <math.h> int main(){ int n, i, factorial = 1; double s = 0, sign = 1.00000; printf("输入n(1~10):"); while(scanf("%d",&n) != EOF) { for(i=1;i<=n;i++) { factorial = factorial * i; sign = pow(-1,i+1); s = s + sign/factorial; continue; } printf("n = %d s = %f\n", n, s); s = 0; factorial = 1; sign = 1.00000; printf("输入n(1~10):"); } return 0; }
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int a,x,y=1; srand(time(0)); x=rand()%31+1; printf("猜猜2020年12月哪一天会是你的luck day\n"); printf("开始喽,你有三次机会,猜吧(1~31): "); scanf("%d",&a); while(y<3) { if(a==x) { printf("你猜的日期是正确的!\n"); break; } else if(a>x) printf("你猜的日期晚了,luck day悄悄溜到前面啦\n"); else printf("你猜的日期早了,luck day还没到呢\n"); printf("再猜(1~31): "); scanf("%d",&a); y++; } if (y>=3) printf("次数用完了,偷偷告诉你:12月,你的luck day是:%d",x); return 0; }
标签:mamicode lse day span 等于 fine rand ble mic
原文地址:https://www.cnblogs.com/Nobel-boy/p/13977840.html