#include<stdio.h> #include<stdlib.h> #include <time.h> #define N 5 int main(){ int x, n; srand(time(0)); for(n=1;n<=N;n++){ x = rand() % 100; printf("%3d", x); } printf("\n"); return 0; }
#include <stdio.h> #include <math.h> void solve(double a, double b, double c); int main(){ double a, b, c; printf("Enter a, b, c: "); while(scanf("%lf%lf%lf", &a, &b, &c) != EOF){ solve(a, b, c); printf("Enter a, b, c: "); } return 0; } void solve(double a, double b, double c){ double x1, x2; double delta, real, imag; if(a == 0) printf("not quadratic equation.\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", x1, x2); } else{ real = -b/(2*a); imag = sqrt(-delta) / (2*a); printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n", real, imag, real, imag); } } }