質問編集履歴
2
エラーの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,6 +24,21 @@
|
|
24
24
|
}
|
25
25
|
return 0;
|
26
26
|
}
|
27
|
+
#fと置く前に実行したときに出るエラー
|
28
|
+
Compilation error #stdin compilation error #stdout 0s 4564KB
|
29
|
+
prog.c: In function ‘main’:
|
30
|
+
prog.c:17:18: error: lvalue required as left operand of assignment
|
31
|
+
else if(b*b-4*a*c=0){
|
32
|
+
^
|
33
|
+
prog.c:6:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
|
34
|
+
scanf("%d\n",&a);
|
35
|
+
^~~~~~~~~~~~~~~~
|
36
|
+
prog.c:8:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
|
37
|
+
scanf("%d\n",&b);
|
38
|
+
^~~~~~~~~~~~~~~~
|
39
|
+
prog.c:10:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
|
40
|
+
scanf("%d\n",&c);
|
41
|
+
^~~~~~~~~~~~~~~~
|
27
42
|
#fと置いた後
|
28
43
|
int main(void) {
|
29
44
|
int a,b,c;
|
1
fと置く前のコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
fと置く前は正常に動作しなかったのでその理由と、a=1,b=0,c=0と代入したときに実数解はありませんとなってしまう理由を教えていただきたいです。
|
2
2
|
|
3
|
-
#include <stdio.h>
|
4
|
-
#
|
3
|
+
#fと置く前
|
5
4
|
int main(void) {
|
6
5
|
int a,b,c;
|
7
6
|
printf("整数 a を入力してください");
|
@@ -10,10 +9,33 @@
|
|
10
9
|
scanf("%d\n",&b);
|
11
10
|
printf("整数 c を入力してください");
|
12
11
|
scanf("%d\n",&c);
|
12
|
+
double d,e;
|
13
|
+
if(b*b-4*a*c>0){
|
14
|
+
d=((double)-b+sqrt((double)b*b-4*a*c))/(2*a);
|
15
|
+
e=((double)-b-sqrt((double)b*b-4*a*c))/(2*a);
|
16
|
+
printf("実数解は%fと%fです",d,e);
|
17
|
+
}
|
18
|
+
else if(b*b-4*a*c=0){
|
19
|
+
d=-b/(2*a);
|
20
|
+
printf("実数解は%f(重解)です",d);
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
printf("実数解はありません");
|
24
|
+
}
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
#fと置いた後
|
28
|
+
int main(void) {
|
29
|
+
int a,b,c;
|
30
|
+
printf("整数 a を入力してください");
|
31
|
+
scanf("%d\n",&a);
|
32
|
+
printf("整数 b を入力してください");
|
33
|
+
scanf("%d\n",&b);
|
34
|
+
printf("整数 c を入力してください");
|
35
|
+
scanf("%d\n",&c);
|
13
36
|
double d,e,f;
|
14
37
|
f = (double)b*b-4*a*c;
|
15
38
|
if(f>0){
|
16
|
-
//fと置かずにやるとエラーが起こった。何故なのか?
|
17
39
|
d=((double)-b+sqrt(f))/(2*a);
|
18
40
|
e=((double)-b-sqrt(f))/(2*a);
|
19
41
|
printf("実数解は%fと%fです",d,e);
|