17, to find the real roots of the equation ax2+bx+c=0 (requires a, B, C values from the keyboard input, a!=0).
1#include <stdio.h>2#include <math.h>3 4 voidMainvoid)5 {6 intA, B, C;7 floatDelta, X1, x2;8 9printf"Input A, B, c:\n");Tenscanf"%d%d%d", &a, &b, &c); OneDelta = b * B-4AC; A if(Delta <0) -printf"No Real root.\n"); - Else the { -X1 = (-B + sqrt (delta))/(2*a); -x2 = (-b-sqrt (delta))/(2*a); -printf"x1 =%f, x2 =%f\n", x1, x2); + } -}
Results:
1.Input A, B, C:
4 8 1
x1 = 2.118034, x2 = 0.118034
2.Input A, B, C:
2 4 3
No Real Root.
3.Input A, B, C:
4 12 9
x1 = 1.500000, x2 = 1.500000
Mark:
If your program uses math library functions, you must add command line # include <math.h> at the beginning of the program
18, write the program to achieve the following functions: Enter a year of the years, to determine whether it is a leap.
1#include <stdio.h>2 3 voidMainvoid)4 {5 intYear , flag;6 7scanf"%d", &Year );8 if(Year% -==0)9Flag =1;Ten Else One { A if(Year%4!=0) -Flag =0; - Else the { - if(Year% -!=0) -Flag =1; - Else +Flag =0 - } + } A if(Flag = =1) atprintf"%d is a leap year.\n", year); - Else -printf"%d is not a leap year.\n", year); -}
19. Write a program that evaluates the values of the following piecewise functions, where the value of x is entered from the keyboard.
1#include <stdio.h>2 {3 floatx, y;4 5printf"Input data:\n");6scanf"%f", &x);7 if(X <0)8y =0;9 Else if(X <Ten)Teny = x * x * x +5; One Else if(X < -) Ay =2* x * x-x-6; - Else if(X < -) -y = x * x +1; the Else -y = x +3; -printf"x =%f, y =%f\n", x, y); -}
20, analyze the following procedure, observe its output.
1#include <stdio.h>2 3 voidMainvoid)4 {5 intA;6 7scanf"%", &a);8 Switch(a)9 {Ten Case 1: printf ("A"); One Case 2: printf ("B"); A Case 3: printf ("C"); Break; - default: printf ("D"); - } the}
Results:
(1) 1
Abc
(2) 2
Bc
(3) 3
C
(4) 4
D
C Language Growth Learning problem (v)