//一元二次方程的 #include#include int main () { double a,b,c,x1,x2; double delat,real,imag; while(scanf("%lf %lf %lf",&a,&b,&c)){ if(a==0) printf("illegal\n"); else{ delat=b*b-4*a*c; if(delat>=0){ x1=-b+sqrt(delat)/(2*a); x2=-b-sqrt(delat)/(2*a); printf("x1=%lf x2=%lf\n",x1,x2); } if(delat<0){ real=-b/(2*a); imag=sqrt(-delat)/(2*a); printf("x1=%lf+%lfi x2=%lf-%lfi\n",real,imag,real,imag); } } printf("ENTER"); } return 0; }
/* 编程找出5个整数的最大数和最小数 《C语言程序设计教程学习指导》p122实验内容(3) */ #include#include int main() { int number, max, min, n; n=1; printf("输入第%d个数: ", n); scanf("%d", &number); max = number; min = number; while(n<=4) { n++; printf("输入第%d个数: ", n); scanf("%d", &number); if(number>max) max = number; else if(number<min) min = number; } printf("最大数为: %d\n", max); printf("最小数为: %d\n", min); system("pause"); return 0; }
#include#include #include int main() { int n;int x;int y;x=0;int z; for(n=101;n<=200;n++) {z=0; for(y=2;y<=sqrt(n);y++) {if( n%y==0) {z=1; break; } } if(z==0) { printf("%4d",n); ++x; if(x%5==0) printf("\n"); } } printf("\n"); printf("101~200之间共有%d个素数",x) ; return 0; }
#include#include int main() { long n; int s;int x;int y; printf("输入一个整数:"); scanf("%ld", &n); s = 0, x = 1; while (n) { y = n % 10; if (y % 2 != 0) { s = s + y * x; x = x * 10; } n = n / 10; } printf("新的数字是:%ld\n", s); return 0; }
感想就是涉及到嵌套式的题目总感觉脑回路不清晰。
#includeint main() { int a,n,x,m=0,b=1; float s=0; printf("Enter n and a:"); scanf("%d%d",&n,&a); for(x=1;x<=n;x++ ) { m=m+a*b; b*=10; s+=(float)x/m; } printf("%f",s); }